diff --git a/pkg/planner/core/collect_column_stats_usage.go b/pkg/planner/core/collect_column_stats_usage.go index dde44d6ff5ff0..d3d5aa877721c 100644 --- a/pkg/planner/core/collect_column_stats_usage.go +++ b/pkg/planner/core/collect_column_stats_usage.go @@ -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) ( diff --git a/pkg/session/session.go b/pkg/session/session.go index 066dbc818910a..8eeebd640392b 100644 --- a/pkg/session/session.go +++ b/pkg/session/session.go @@ -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) diff --git a/pkg/statistics/histogram.go b/pkg/statistics/histogram.go index 0db2e88a7ed5b..2b3f3225af8d1 100644 --- a/pkg/statistics/histogram.go +++ b/pkg/statistics/histogram.go @@ -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)