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: reuse fm sketch when to analyze #47268

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
executor: reuse fm sketch when to analyze
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Sep 25, 2023
commit f8a15daae3774ecc155270da2c9a4dc72caf9d51
2 changes: 2 additions & 0 deletions executor/analyze_col_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ func (e *AnalyzeColumnsExecV2) buildSamplingStats(
mergeResult.collector.Base().Count, e.tableID.TableID, e.tableID.PartitionID, e.tableID.IsPartitionTable(),
"merge subMergeWorker in AnalyzeColumnsExecV2", -1)
e.memTracker.Consume(rootRowCollector.Base().MemSize - oldRootCollectorSize - mergeResult.collector.Base().MemSize)
mergeResult.collector.DestroyAndPutToPool()
}
defer e.memTracker.Release(rootRowCollector.Base().MemSize)
if err != nil {
Expand Down Expand Up @@ -668,6 +669,7 @@ func (e *AnalyzeColumnsExecV2) subMergeWorker(resultCh chan<- *samplingMergeResu
subCollectorSize := subCollector.Base().MemSize
e.memTracker.Consume(newRetCollectorSize - oldRetCollectorSize - subCollectorSize)
e.memTracker.Release(dataSize + colRespSize)
subCollector.DestroyAndPutToPool()
}

resultCh <- &samplingMergeResult{collector: retCollector}
Expand Down
17 changes: 17 additions & 0 deletions statistics/row_sampler.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type RowSampleCollector interface {
MergeCollector(collector RowSampleCollector)
sampleRow(row []types.Datum, rng *rand.Rand)
Base() *baseCollector
DestroyAndPutToPool()
}

type baseCollector struct {
Expand Down Expand Up @@ -228,6 +229,12 @@ func (s *RowSampleBuilder) Collect() (RowSampleCollector, error) {
return collector, nil
}

func (s *baseCollector) destroyAndPutToPool() {
for _, sketch := range s.FMSketches {
sketch.DestroyAndPutToPool()
}
}

func (s *baseCollector) collectColumns(sc *stmtctx.StatementContext, cols []types.Datum, sizes []int64) error {
for i, col := range cols {
if col.IsNull() {
Expand Down Expand Up @@ -389,6 +396,11 @@ func (s *ReservoirRowSampleCollector) MergeCollector(subCollector RowSampleColle
}
}

// DestroyAndPutToPool implements the interface RowSampleCollector.
func (s *ReservoirRowSampleCollector) DestroyAndPutToPool() {
s.baseCollector.destroyAndPutToPool()
}

// RowSamplesToProto converts the samp slice to the pb struct.
func RowSamplesToProto(samples WeightedRowSampleHeap) []*tipb.RowSample {
if len(samples) == 0 {
Expand Down Expand Up @@ -472,3 +484,8 @@ func (s *BernoulliRowSampleCollector) MergeCollector(subCollector RowSampleColle
func (s *BernoulliRowSampleCollector) Base() *baseCollector {
return s.baseCollector
}

// DestroyAndPutToPool implements the interface RowSampleCollector.
func (s *BernoulliRowSampleCollector) DestroyAndPutToPool() {
s.baseCollector.destroyAndPutToPool()
}