Skip to content

Recursive CTE didn't track memory accurately #54181

@guo-shaoge

Description

@guo-shaoge

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

// Reopen impls Storage Reopen interface.
func (s *StorageRC) Reopen() (err error) {
if err = s.rc.Close(); err != nil {
return err
}
s.iter = 0
s.done = false
s.err = nil
// Create a new RowContainer.
// Because some meta infos in old RowContainer are not resetted.
// Such as memTracker/actionSpill etc. So we just use a new one.
s.rc = chunk.NewRowContainer(s.tp, s.chkSize)
return nil
}

L167 create a new row container after each CTE iteration. But it didn't attach memtracker to session tracker, so the memory control will not work correctly.

Specifically, the memory control for resTbl of CTE is as expected, but after one iteration of the CTE computation, the memory usage of iterInTbl and iterOutTbl cannot be accurately tracked (and they also cannot be spilled to disk) because of above bug.

2. What did you expect to see? (Required)

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

Metadata

Metadata

Assignees

Labels

affects-5.4This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.2report/customerCustomers have encountered this bug.severity/majorsig/executionSIG executiontype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions