Skip to content

Commit

Permalink
executor: add memory tracker for memtableRetriever (#51455) (#52823)
Browse files Browse the repository at this point in the history
close #51456
  • Loading branch information
ti-chi-bot authored Apr 23, 2024
1 parent 971fec0 commit 5e7a36d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2003,13 +2003,16 @@ func (b *executorBuilder) buildMemTable(v *plannercore.PhysicalMemTable) Executo
strings.ToLower(infoschema.ClusterTableMemoryUsage),
strings.ToLower(infoschema.ClusterTableMemoryUsageOpsHistory),
strings.ToLower(infoschema.TableResourceGroups):
memTracker := memory.NewTracker(v.ID(), -1)
memTracker.AttachTo(b.ctx.GetSessionVars().StmtCtx.MemTracker)
return &MemTableReaderExec{
baseExecutor: 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 executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type memtableRetriever struct {
retrieved bool
initialized bool
extractor plannercore.MemTablePredicateExtractor
memTracker *memory.Tracker
}

// retrieve implements the infoschemaRetriever interface
Expand Down Expand Up @@ -190,6 +191,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

0 comments on commit 5e7a36d

Please sign in to comment.