Skip to content

Commit

Permalink
update var name according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
time-and-fate committed Apr 1, 2024
1 parent 65c5878 commit 6758bd7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
8 changes: 4 additions & 4 deletions pkg/planner/cardinality/cross_estimation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions pkg/planner/cardinality/row_count_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/planner/cardinality/row_count_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6758bd7

Please sign in to comment.