From 6758bd74561dd0d5a69b8a95421ce1255bb60647 Mon Sep 17 00:00:00 2001 From: time-and-fate <25057648+time-and-fate@users.noreply.github.com> Date: Mon, 1 Apr 2024 17:25:46 +0800 Subject: [PATCH] update var name according to comments --- pkg/planner/cardinality/cross_estimation.go | 8 +++---- pkg/planner/cardinality/row_count_column.go | 24 ++++++++++----------- pkg/planner/cardinality/row_count_index.go | 14 ++++++------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pkg/planner/cardinality/cross_estimation.go b/pkg/planner/cardinality/cross_estimation.go index df6052d2b2198..3aa618e3307df 100644 --- a/pkg/planner/cardinality/cross_estimation.go +++ b/pkg/planner/cardinality/cross_estimation.go @@ -139,7 +139,7 @@ func crossEstimateRowCount(sctx context.PlanContext, if col == nil || len(path.AccessConds) > 0 { return 0, false, corr } - colID := col.UniqueID + colUniqueID := col.UniqueID if corr < 0 { desc = !desc } @@ -152,11 +152,11 @@ func crossEstimateRowCount(sctx context.PlanContext, return 0, err == nil, corr } idxID := int64(-1) - idxIDs, idxExists := dsStatsInfo.HistColl.ColUniqueID2IdxIDs[colID] + idxIDs, idxExists := dsStatsInfo.HistColl.ColUniqueID2IdxIDs[colUniqueID] if idxExists && len(idxIDs) > 0 { idxID = idxIDs[0] } - rangeCounts, ok := getColumnRangeCounts(sctx, colID, ranges, dsTableStats.HistColl, idxID) + rangeCounts, ok := getColumnRangeCounts(sctx, colUniqueID, ranges, dsTableStats.HistColl, idxID) if !ok { return 0, false, corr } @@ -168,7 +168,7 @@ func crossEstimateRowCount(sctx context.PlanContext, if idxExists { rangeCount, err = GetRowCountByIndexRanges(sctx, dsTableStats.HistColl, idxID, convertedRanges) } else { - rangeCount, err = GetRowCountByColumnRanges(sctx, dsTableStats.HistColl, colID, convertedRanges) + rangeCount, err = GetRowCountByColumnRanges(sctx, dsTableStats.HistColl, colUniqueID, convertedRanges) } if err != nil { return 0, false, corr diff --git a/pkg/planner/cardinality/row_count_column.go b/pkg/planner/cardinality/row_count_column.go index 4373cc86e41c6..fad100d82c358 100644 --- a/pkg/planner/cardinality/row_count_column.go +++ b/pkg/planner/cardinality/row_count_column.go @@ -33,27 +33,27 @@ func init() { } // GetRowCountByColumnRanges estimates the row count by a slice of Range. -func GetRowCountByColumnRanges(sctx context.PlanContext, coll *statistics.HistColl, colID int64, colRanges []*ranger.Range) (result float64, err error) { +func GetRowCountByColumnRanges(sctx context.PlanContext, coll *statistics.HistColl, colUniqueID int64, colRanges []*ranger.Range) (result float64, err error) { var name string if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) - debugTraceGetRowCountInput(sctx, colID, colRanges) + debugTraceGetRowCountInput(sctx, colUniqueID, colRanges) defer func() { debugtrace.RecordAnyValuesWithNames(sctx, "Name", name, "Result", result) debugtrace.LeaveContextCommon(sctx) }() } sc := sctx.GetSessionVars().StmtCtx - c, ok := coll.Columns[colID] - colInfoID := colID + c, ok := coll.Columns[colUniqueID] + colInfoID := colUniqueID if len(coll.UniqueID2colInfoID) > 0 { - colInfoID = coll.UniqueID2colInfoID[colID] + colInfoID = coll.UniqueID2colInfoID[colUniqueID] } recordUsedItemStatsStatus(sctx, c, coll.PhysicalID, colInfoID) if c != nil && c.Info != nil { name = c.Info.Name.O } - if statistics.ColumnStatsIsInvalid(c, sctx, coll, colID) { + if statistics.ColumnStatsIsInvalid(c, sctx, coll, colUniqueID) { result, err = getPseudoRowCountByColumnRanges(sc.TypeCtx(), float64(coll.RealtimeCount), colRanges, 0) if err == nil && sc.EnableOptimizerCETrace && ok { ceTraceRange(sctx, coll.PhysicalID, []string{c.Info.Name.O}, colRanges, "Column Stats-Pseudo", uint64(result)) @@ -75,27 +75,27 @@ func GetRowCountByColumnRanges(sctx context.PlanContext, coll *statistics.HistCo } // GetRowCountByIntColumnRanges estimates the row count by a slice of IntColumnRange. -func GetRowCountByIntColumnRanges(sctx context.PlanContext, coll *statistics.HistColl, colID int64, intRanges []*ranger.Range) (result float64, err error) { +func GetRowCountByIntColumnRanges(sctx context.PlanContext, coll *statistics.HistColl, colUniqueID int64, intRanges []*ranger.Range) (result float64, err error) { var name string if sctx.GetSessionVars().StmtCtx.EnableOptimizerDebugTrace { debugtrace.EnterContextCommon(sctx) - debugTraceGetRowCountInput(sctx, colID, intRanges) + debugTraceGetRowCountInput(sctx, colUniqueID, intRanges) defer func() { debugtrace.RecordAnyValuesWithNames(sctx, "Name", name, "Result", result) debugtrace.LeaveContextCommon(sctx) }() } sc := sctx.GetSessionVars().StmtCtx - c, ok := coll.Columns[colID] - colInfoID := colID + c, ok := coll.Columns[colUniqueID] + colInfoID := colUniqueID if len(coll.UniqueID2colInfoID) > 0 { - colInfoID = coll.UniqueID2colInfoID[colID] + colInfoID = coll.UniqueID2colInfoID[colUniqueID] } recordUsedItemStatsStatus(sctx, c, coll.PhysicalID, colInfoID) if c != nil && c.Info != nil { name = c.Info.Name.O } - if statistics.ColumnStatsIsInvalid(c, sctx, coll, colID) { + if statistics.ColumnStatsIsInvalid(c, sctx, coll, colUniqueID) { if len(intRanges) == 0 { return 0, nil } diff --git a/pkg/planner/cardinality/row_count_index.go b/pkg/planner/cardinality/row_count_index.go index 4b346bcb231f7..692696b3e1b9d 100644 --- a/pkg/planner/cardinality/row_count_index.go +++ b/pkg/planner/cardinality/row_count_index.go @@ -170,19 +170,19 @@ func getIndexRowCountForStatsV1(sctx context.PlanContext, coll *statistics.HistC } var count float64 var err error - colIDs := coll.Idx2ColUniqueIDs[idxID] - var colID int64 - if rangePosition >= len(colIDs) { - colID = -1 + colUniqueIDs := coll.Idx2ColUniqueIDs[idxID] + var colUniqueID int64 + if rangePosition >= len(colUniqueIDs) { + colUniqueID = -1 } else { - colID = colIDs[rangePosition] + colUniqueID = colUniqueIDs[rangePosition] } // prefer index stats over column stats - if idxIDs, ok := coll.ColUniqueID2IdxIDs[colID]; ok && len(idxIDs) > 0 { + if idxIDs, ok := coll.ColUniqueID2IdxIDs[colUniqueID]; ok && len(idxIDs) > 0 { idxID := idxIDs[0] count, err = GetRowCountByIndexRanges(sctx, coll, idxID, []*ranger.Range{&rang}) } else { - count, err = GetRowCountByColumnRanges(sctx, coll, colID, []*ranger.Range{&rang}) + count, err = GetRowCountByColumnRanges(sctx, coll, colUniqueID, []*ranger.Range{&rang}) } if err != nil { return 0, errors.Trace(err)