Skip to content

Commit

Permalink
planner: remove useless check (#54907)
Browse files Browse the repository at this point in the history
ref #54883
  • Loading branch information
Rustin170506 authored Jul 25, 2024
1 parent 77c97ef commit ee64347
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pkg/planner/core/collect_column_stats_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func (c *columnStatsUsageCollector) collectFromPlan(lp base.LogicalPlan) {

// CollectColumnStatsUsage collects column stats usage from logical plan.
// predicate indicates whether to collect predicate columns and histNeeded indicates whether to collect histogram-needed columns.
// First return value: predicate columns (nil if predicate is false)
// First return value: predicate columns
// Second return value: histogram-needed columns (nil if histNeeded is false)
// Third return value: ds.PhysicalTableID from all DataSource (always collected)
func CollectColumnStatsUsage(lp base.LogicalPlan, histNeeded bool) (
Expand Down
5 changes: 2 additions & 3 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,8 @@ func (s *session) UpdateColStatsUsage(predicateColumns []model.TableItemID) {
t := time.Now()
colMap := make(map[model.TableItemID]time.Time, len(predicateColumns))
for _, col := range predicateColumns {
if col.IsIndex {
continue
}
// TODO: Remove this assertion once it has been confirmed to operate correctly over a period of time.
intest.Assert(!col.IsIndex, "predicate column should only be table column")
colMap[col] = t
}
s.statsCollector.UpdateColStatsUsage(colMap)
Expand Down
31 changes: 0 additions & 31 deletions pkg/statistics/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,37 +422,6 @@ func (hg *Histogram) StandardizeForV2AnalyzeIndex() {
hg.Bounds = c
}

// AddIdxVals adds the given values to the histogram.
func (hg *Histogram) AddIdxVals(idxValCntPairs []TopNMeta) {
totalAddCnt := int64(0)
slices.SortFunc(idxValCntPairs, func(i, j TopNMeta) int {
return bytes.Compare(i.Encoded, j.Encoded)
})
for bktIdx, pairIdx := 0, 0; bktIdx < hg.Len(); bktIdx++ {
for pairIdx < len(idxValCntPairs) {
// If the current val smaller than current bucket's lower bound, skip it.
cmpResult := bytes.Compare(hg.Bounds.Column(0).GetBytes(bktIdx*2), idxValCntPairs[pairIdx].Encoded)
if cmpResult > 0 {
continue
}
// If the current val bigger than current bucket's upper bound, break.
cmpResult = bytes.Compare(hg.Bounds.Column(0).GetBytes(bktIdx*2+1), idxValCntPairs[pairIdx].Encoded)
if cmpResult < 0 {
break
}
totalAddCnt += int64(idxValCntPairs[pairIdx].Count)
hg.Buckets[bktIdx].NDV++
if cmpResult == 0 {
hg.Buckets[bktIdx].Repeat = int64(idxValCntPairs[pairIdx].Count)
pairIdx++
break
}
pairIdx++
}
hg.Buckets[bktIdx].Count += totalAddCnt
}
}

// ToString gets the string representation for the histogram.
func (hg *Histogram) ToString(idxCols int) string {
strs := make([]string, 0, hg.Len()+1)
Expand Down

0 comments on commit ee64347

Please sign in to comment.