Skip to content

Commit 870bfd9

Browse files
committed
update
Signed-off-by: Weizhen Wang <[email protected]>
1 parent 4e16aef commit 870bfd9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pkg/expression/grouping_sets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ func (gs GroupingSet) AllColIDs() *intset.FastIntSet {
242242
}
243243

244244
// ExtractCols is used to extract basic columns from one grouping set.
245-
func (gs GroupingSet) ExtractCols() []*Column {
246-
cols := make([]*Column, 0, len(gs))
245+
// the param cols is used for reuse the slice.
246+
func (gs GroupingSet) ExtractCols(cols []*Column) []*Column {
247247
for _, groupingExprs := range gs {
248248
for _, one := range groupingExprs {
249249
cols = append(cols, one.(*Column))

pkg/planner/core/task.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,11 +1582,13 @@ func scaleStats4GroupingSets(p *physicalop.PhysicalHashAgg, groupingSets express
15821582
}
15831583
}
15841584
sumNDV := float64(0)
1585+
groupingSetCols := make([]*expression.Column, 0, 4)
15851586
for _, groupingSet := range groupingSets {
15861587
// for every grouping set, pick its cols out, and combine with normal group cols to get the ndv.
1587-
groupingSetCols := groupingSet.ExtractCols()
1588+
groupingSetCols = groupingSet.ExtractCols(groupingSetCols)
15881589
groupingSetCols = append(groupingSetCols, normalGbyCols...)
15891590
ndv, _ := cardinality.EstimateColsNDVWithMatchedLen(p.SCtx(), groupingSetCols, childSchema, childStats)
1591+
groupingSetCols = groupingSetCols[:0]
15901592
sumNDV += ndv
15911593
}
15921594
// After group operator, all same rows are grouped into one row, that means all

0 commit comments

Comments
 (0)