Skip to content

Commit

Permalink
executor: add memory tracker for memtableRetriever (#51455)
Browse files Browse the repository at this point in the history
close #51456
  • Loading branch information
wshwsh12 authored Mar 5, 2024
1 parent 6566269 commit 4f4f911
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/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) exec.Ex
strings.ToLower(infoschema.TableKeywords),
strings.ToLower(infoschema.TableTiDBIndexUsage),
strings.ToLower(infoschema.ClusterTableTiDBIndexUsage):
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 @@ -95,6 +95,7 @@ type memtableRetriever struct {
retrieved bool
initialized bool
extractor plannercore.MemTablePredicateExtractor
memTracker *memory.Tracker
}

// retrieve implements the infoschemaRetriever interface
Expand Down Expand Up @@ -210,6 +211,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 4f4f911

Please sign in to comment.