Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: add memory tracker for memtableRetriever (#51455) #53068

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pkg/executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2098,13 +2098,16 @@ func (b *executorBuilder) buildMemTable(v *plannercore.PhysicalMemTable) exec.Ex
strings.ToLower(infoschema.TableResourceGroups),
strings.ToLower(infoschema.TableRunawayWatches),
strings.ToLower(infoschema.TableCheckConstraints):
memTracker := memory.NewTracker(v.ID(), -1)
memTracker.AttachTo(b.ctx.GetSessionVars().StmtCtx.MemTracker)
return &MemTableReaderExec{
BaseExecutor: exec.NewBaseExecutor(b.ctx, v.Schema(), v.ID()),
table: v.Table,
retriever: &memtableRetriever{
table: v.Table,
columns: v.Columns,
extractor: v.Extractor,
table: v.Table,
columns: v.Columns,
extractor: v.Extractor,
memTracker: memTracker,
},
}
case strings.ToLower(infoschema.TableTiDBTrx),
Expand Down
4 changes: 4 additions & 0 deletions pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type memtableRetriever struct {
retrieved bool
initialized bool
extractor plannercore.MemTablePredicateExtractor
memTracker *memory.Tracker
}

// retrieve implements the infoschemaRetriever interface
Expand Down Expand Up @@ -201,6 +202,9 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex
return nil, err
}
e.initialized = true
if e.memTracker != nil {
e.memTracker.Consume(calculateDatumsSize(e.rows))
}
}

// Adjust the amount of each return
Expand Down