diff --git a/build/nogo_config.json b/build/nogo_config.json index 50806eef4fe08..06d746067620f 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -491,27 +491,18 @@ ".*_test\\.go$": "ignore generated code", ".*_generated\\.go$": "ignore generated code", "planner/core/resolve_indices.go": "planner/core/resolve_indices.go", - "planner/core/rule_result_reorder.go": "planner/core/rule_result_reorder.go", - "planner/core/rule_join_reorder_dp.go": "planner/core/rule_join_reorder_dp.go", - "planner/core/plan_cache_param.go": "planner/core/plan_cache_param.go", - "planner/core/rule_predicate_push_down.go": "planner/core/rule_predicate_push_down.go", "planner/core/rule_aggregation_push_down.go": "planner/core/rule_aggregation_push_down.go", - "planner/core/rule_max_min_eliminate.go": "planner/core/rule_max_min_eliminate.go", - "planner/core/rule_predicate_simplification.go": "planner/core/rule_predicate_simplification.go", + "planner/core/rule_max_min_eliminate.go": "planner/core/rule_max_min_eliminate.go", "planner/core/indexmerge_path.go": "planner/core/indexmerge_path.go", "planner/core/rule_join_reorder.go": "planner/core/rule_join_reorder.go", "planner/core/plan_cacheable_checker.go": "planner/core/plan_cacheable_checker.go", "planner/core/rule_decorrelate.go": "planner/core/rule_decorrelate.go", "planner/core/plan_cache_utils.go": "planner/core/plan_cache_utils.go", "planner/core/rule_aggregation_skew_rewrite.go": "planner/core/rule_aggregation_skew_rewrite.go", - "planner/core/rule_topn_push_down.go": "planner/core/rule_topn_push_down.go", - "planner/core/plan_cost_ver1.go": "planner/core/plan_cost_ver1.go", - "planner/core/expression_rewriter.go": "planner/core/expression_rewriter.go", - "planner/core/find_best_task.go": "planner/core/find_best_task.go", + "planner/core/rule_topn_push_down.go": "planner/core/rule_topn_push_down.go", + "planner/core/expression_rewriter.go": "planner/core/expression_rewriter.go", "planner/core/task.go": "planner/core/task.go", - "planner/core/preprocess.go": "planner/core/preprocess.go", - "planner/core/rule_partition_processor.go": "planner/core/rule_partition_processor.go", - "planner/core/exhaust_physical_plans.go": "planner/core/exhaust_physical_plans.go", + "planner/core/preprocess.go": "planner/core/preprocess.go", "planner/core/plan_cache_lru.go": "planner/core/plan_cache_lru.go", "planner/core/common_plans.go": "planner/core/common_plans.go", "plugin/conn_ip_example/": "plugin/conn_ip_example/" diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index 6a59daa6af892..119c6497ac8e2 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -139,7 +139,7 @@ func (p *PhysicalMergeJoin) tryToGetChildReqProp(prop *property.PhysicalProperty return []*property.PhysicalProperty{lProp, rProp}, true } -func (p *LogicalJoin) checkJoinKeyCollation(leftKeys, rightKeys []*expression.Column) bool { +func (*LogicalJoin) checkJoinKeyCollation(leftKeys, rightKeys []*expression.Column) bool { // if a left key and its corresponding right key have different collation, don't use MergeJoin since // the their children may sort their records in different ways for i := range leftKeys { @@ -1022,7 +1022,7 @@ func (ijHelper *indexJoinBuildHelper) buildRangeDecidedByInformation(idxCols []* func (p *LogicalJoin) constructInnerTableScanTask( wrapper *indexJoinInnerChildWrapper, ranges ranger.Ranges, - outerJoinKeys []*expression.Column, + _ []*expression.Column, rangeInfo string, keepOrder bool, desc bool, @@ -1115,7 +1115,7 @@ func (p *LogicalJoin) constructInnerByWrapper(wrapper *indexJoinInnerChildWrappe return child } -func (p *LogicalJoin) constructInnerSel(sel *LogicalSelection, child PhysicalPlan) PhysicalPlan { +func (*LogicalJoin) constructInnerSel(sel *LogicalSelection, child PhysicalPlan) PhysicalPlan { if sel == nil { return child } @@ -1126,7 +1126,7 @@ func (p *LogicalJoin) constructInnerSel(sel *LogicalSelection, child PhysicalPla return physicalSel } -func (p *LogicalJoin) constructInnerProj(proj *LogicalProjection, child PhysicalPlan) PhysicalPlan { +func (*LogicalJoin) constructInnerProj(proj *LogicalProjection, child PhysicalPlan) PhysicalPlan { if proj == nil { return child } @@ -1139,7 +1139,7 @@ func (p *LogicalJoin) constructInnerProj(proj *LogicalProjection, child Physical return physicalProj } -func (p *LogicalJoin) constructInnerUnionScan(us *LogicalUnionScan, reader PhysicalPlan) PhysicalPlan { +func (*LogicalJoin) constructInnerUnionScan(us *LogicalUnionScan, reader PhysicalPlan) PhysicalPlan { if us == nil { return reader } @@ -1153,76 +1153,13 @@ func (p *LogicalJoin) constructInnerUnionScan(us *LogicalUnionScan, reader Physi return physicalUnionScan } -func getColsNDVLowerBoundFromHistColl(cols []*expression.Column, histColl *statistics.HistColl) int64 { - if len(cols) == 0 || histColl == nil { - return -1 - } - colUIDs := make([]int64, len(cols)) - for i, col := range cols { - colUIDs[i] = col.UniqueID - } - - // Note that we don't need to specially handle prefix index in this function, because the NDV of a prefix index is - // equal or less than the corresponding normal index, and that's safe here since we want a lower bound. - - // 1. Try to get NDV from column stats if it's a single column. - if len(colUIDs) == 1 && histColl.Columns != nil { - uid := colUIDs[0] - if colStats, ok := histColl.Columns[uid]; ok && colStats != nil { - return colStats.NDV - } - } - - slices.Sort(colUIDs) - if histColl.Indices == nil || histColl.Idx2ColumnIDs == nil { - return -1 - } - - // 2. Try to get NDV from index stats. - for idxID, idxCols := range histColl.Idx2ColumnIDs { - if len(idxCols) != len(colUIDs) { - continue - } - orderedIdxCols := make([]int64, len(idxCols)) - copy(orderedIdxCols, idxCols) - slices.Sort(orderedIdxCols) - if !slices.Equal(orderedIdxCols, colUIDs) { - continue - } - if idxStats, ok := histColl.Indices[idxID]; ok && idxStats != nil { - return idxStats.NDV - } - } - - // TODO: if there's an index that contains the expected columns, we can also make use of its NDV. - // For example, NDV(a,b,c) / NDV(c) is a safe lower bound of NDV(a,b). - - // 3. If we still haven't got an NDV, we use the minimal NDV in the column stats as a lower bound. - // This would happen when len(cols) > 1 and no proper index stats are available. - minNDV := int64(-1) - for _, colStats := range histColl.Columns { - if colStats == nil || colStats.Info == nil { - continue - } - col := colStats.Info - if col.IsGenerated() && !col.GeneratedStored { - continue - } - if (colStats.NDV > 0 && minNDV <= 0) || - colStats.NDV < minNDV { - minNDV = colStats.NDV - } - } - return minNDV -} - // constructInnerIndexScanTask is specially used to construct the inner plan for PhysicalIndexJoin. func (p *LogicalJoin) constructInnerIndexScanTask( wrapper *indexJoinInnerChildWrapper, path *util.AccessPath, ranges ranger.Ranges, filterConds []expression.Expression, - innerJoinKeys []*expression.Column, + _ []*expression.Column, rangeInfo string, keepOrder bool, desc bool, @@ -2092,18 +2029,18 @@ func checkChildFitBC(p Plan) bool { return p.SCtx().GetSessionVars().BroadcastJoinThresholdSize == -1 || sz < float64(p.SCtx().GetSessionVars().BroadcastJoinThresholdSize) } -func calcBroadcastExchangeSize(p Plan, mppStoreCnt int) (float64, float64, bool) { +func calcBroadcastExchangeSize(p Plan, mppStoreCnt int) (row float64, size float64, hasSize bool) { s := p.statsInfo() - row := float64(s.Count()) * float64(mppStoreCnt-1) + row = float64(s.Count()) * float64(mppStoreCnt-1) if s.HistColl == nil { return row, 0, false } avg := s.HistColl.GetAvgRowSize(p.SCtx(), p.Schema().Columns, false, false) - size := avg * row + size = avg * row return row, size, true } -func calcBroadcastExchangeSizeByChild(p1 Plan, p2 Plan, mppStoreCnt int) (float64, float64, bool) { +func calcBroadcastExchangeSizeByChild(p1 Plan, p2 Plan, mppStoreCnt int) (row float64, size float64, hasSize bool) { row1, size1, hasSize1 := calcBroadcastExchangeSize(p1, mppStoreCnt) row2, size2, hasSize2 := calcBroadcastExchangeSize(p2, mppStoreCnt) @@ -2119,18 +2056,18 @@ func calcBroadcastExchangeSizeByChild(p1 Plan, p2 Plan, mppStoreCnt int) (float6 return math.Min(row1, row2), 0, false } -func calcHashExchangeSize(p Plan, mppStoreCnt int) (float64, float64, bool) { +func calcHashExchangeSize(p Plan, mppStoreCnt int) (row float64, sz float64, hasSize bool) { s := p.statsInfo() - row := float64(s.Count()) * float64(mppStoreCnt-1) / float64(mppStoreCnt) + row = float64(s.Count()) * float64(mppStoreCnt-1) / float64(mppStoreCnt) if s.HistColl == nil { return row, 0, false } avg := s.HistColl.GetAvgRowSize(p.SCtx(), p.Schema().Columns, false, false) - sz := avg * row + sz = avg * row return row, sz, true } -func calcHashExchangeSizeByChild(p1 Plan, p2 Plan, mppStoreCnt int) (float64, float64, bool) { +func calcHashExchangeSizeByChild(p1 Plan, p2 Plan, mppStoreCnt int) (row float64, size float64, hasSize bool) { row1, size1, hasSize1 := calcHashExchangeSize(p1, mppStoreCnt) row2, size2, hasSize2 := calcHashExchangeSize(p2, mppStoreCnt) @@ -2867,7 +2804,7 @@ func (lw *LogicalWindow) exhaustPhysicalPlans(prop *property.PhysicalProperty) ( } // exhaustPhysicalPlans is only for implementing interface. DataSource and Dual generate task in `findBestTask` directly. -func (p *baseLogicalPlan) exhaustPhysicalPlans(_ *property.PhysicalProperty) ([]PhysicalPlan, bool, error) { +func (*baseLogicalPlan) exhaustPhysicalPlans(*property.PhysicalProperty) ([]PhysicalPlan, bool, error) { panic("baseLogicalPlan.exhaustPhysicalPlans() should never be called.") } diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index edd0f4a094daa..aefe19864fc2a 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -783,7 +783,7 @@ func (ds *DataSource) getIndexCandidate(path *util.AccessPath, prop *property.Ph return candidate } -func (ds *DataSource) getIndexMergeCandidate(path *util.AccessPath) *candidatePath { +func (*DataSource) getIndexMergeCandidate(path *util.AccessPath) *candidatePath { candidate := &candidatePath{path: path} return candidate } @@ -1123,9 +1123,9 @@ func (ds *DataSource) findBestTask(prop *property.PhysicalProperty, planCounter if allRangeIsPoint { var pointGetTask task if len(path.Ranges) == 1 { - pointGetTask = ds.convertToPointGet(prop, candidate, opt) + pointGetTask = ds.convertToPointGet(prop, candidate) } else { - pointGetTask = ds.convertToBatchPointGet(prop, candidate, hashPartColName, opt) + pointGetTask = ds.convertToBatchPointGet(prop, candidate, hashPartColName) } // Batch/PointGet plans may be over-optimized, like `a>=1(?) and a<=1(?)` --> `a=1` --> PointGet(a=1). @@ -1213,7 +1213,7 @@ func (ds *DataSource) findBestTask(prop *property.PhysicalProperty, planCounter return } -func (ds *DataSource) isSafePointGetPlan4PlanCache(path *util.AccessPath) bool { +func (*DataSource) isSafePointGetPlan4PlanCache(path *util.AccessPath) bool { // PointGet might contain some over-optimized assumptions, like `a>=1 and a<=1` --> `a=1`, but // these assumptions may be broken after parameters change. @@ -2307,7 +2307,7 @@ func (ds *DataSource) convertToSampleTable(prop *property.PhysicalProperty, }, nil } -func (ds *DataSource) convertToPointGet(prop *property.PhysicalProperty, candidate *candidatePath, opt *physicalOptimizeOp) (task task) { +func (ds *DataSource) convertToPointGet(prop *property.PhysicalProperty, candidate *candidatePath) (task task) { if !prop.IsSortItemEmpty() && !candidate.isMatchProp { return invalidTask } @@ -2384,8 +2384,7 @@ func (ds *DataSource) convertToPointGet(prop *property.PhysicalProperty, candida return rTsk } -func (ds *DataSource) convertToBatchPointGet(prop *property.PhysicalProperty, - candidate *candidatePath, hashPartColName *model.CIStr, opt *physicalOptimizeOp) (task task) { +func (ds *DataSource) convertToBatchPointGet(prop *property.PhysicalProperty, candidate *candidatePath, hashPartColName *model.CIStr) (task task) { if !prop.IsSortItemEmpty() && !candidate.isMatchProp { return invalidTask } diff --git a/planner/core/plan_cache_param.go b/planner/core/plan_cache_param.go index 9beae0a88e457..ca66199aa3c43 100644 --- a/planner/core/plan_cache_param.go +++ b/planner/core/plan_cache_param.go @@ -16,7 +16,6 @@ package core import ( "bytes" - "context" "errors" "sync" @@ -83,7 +82,7 @@ func (pr *paramReplacer) Enter(in ast.Node) (out ast.Node, skipChildren bool) { return in, false } -func (pr *paramReplacer) Leave(in ast.Node) (out ast.Node, ok bool) { +func (*paramReplacer) Leave(in ast.Node) (out ast.Node, ok bool) { return in, true } @@ -94,9 +93,9 @@ func (pr *paramReplacer) Reset() { // GetParamSQLFromAST returns the parameterized SQL of this AST. // NOTICE: this function does not modify the original AST. // paramVals are copied from this AST. -func GetParamSQLFromAST(ctx context.Context, sctx sessionctx.Context, stmt ast.StmtNode) (paramSQL string, paramVals []types.Datum, err error) { +func GetParamSQLFromAST(sctx sessionctx.Context, stmt ast.StmtNode) (paramSQL string, paramVals []types.Datum, err error) { var params []*driver.ValueExpr - paramSQL, params, err = ParameterizeAST(ctx, sctx, stmt) + paramSQL, params, err = ParameterizeAST(stmt) if err != nil { return "", nil, err } @@ -105,14 +104,14 @@ func GetParamSQLFromAST(ctx context.Context, sctx sessionctx.Context, stmt ast.S p.Datum.Copy(¶mVals[i]) } - err = RestoreASTWithParams(ctx, sctx, stmt, params) + err = RestoreASTWithParams(sctx, stmt, params) return } // ParameterizeAST parameterizes this StmtNode. // e.g. `select * from t where a<10 and b<23` --> `select * from t where a= len(pr.params) { pr.err = errors.New("failed to restore ast.Node") return nil, true @@ -152,7 +150,7 @@ func (pr *paramRestorer) Enter(in ast.Node) (out ast.Node, skipChildren bool) { return in, false } -func (pr *paramRestorer) Leave(in ast.Node) (out ast.Node, ok bool) { +func (*paramRestorer) Leave(in ast.Node) (out ast.Node, ok bool) { return in, true } @@ -162,7 +160,7 @@ func (pr *paramRestorer) Reset() { // RestoreASTWithParams restore this parameterized AST with specific parameters. // e.g. `select * from t where a `select * from t where a<10 and b<23`. -func RestoreASTWithParams(ctx context.Context, _ sessionctx.Context, stmt ast.StmtNode, params []*driver.ValueExpr) error { +func RestoreASTWithParams(_ sessionctx.Context, stmt ast.StmtNode, params []*driver.ValueExpr) error { pr := paramRestorerPool.Get().(*paramRestorer) defer func() { pr.Reset() diff --git a/planner/core/plan_cache_param_test.go b/planner/core/plan_cache_param_test.go index cd98b3ac683d0..4009a9fa2c02a 100644 --- a/planner/core/plan_cache_param_test.go +++ b/planner/core/plan_cache_param_test.go @@ -15,7 +15,6 @@ package core import ( - "context" "fmt" "math/rand" "sync" @@ -28,7 +27,6 @@ import ( ) func TestParameterize(t *testing.T) { - sctx := MockContext() cases := []struct { sql string paramSQL string @@ -112,7 +110,7 @@ func TestParameterize(t *testing.T) { for _, c := range cases { stmt, err := parser.New().ParseOneStmt(c.sql, "", "") require.Nil(t, err) - paramSQL, params, err := ParameterizeAST(context.Background(), sctx, stmt) + paramSQL, params, err := ParameterizeAST(stmt) require.Nil(t, err) require.Equal(t, c.paramSQL, paramSQL) require.Equal(t, len(c.params), len(params)) @@ -140,7 +138,7 @@ func TestGetParamSQLFromASTConcurrently(t *testing.T) { wg.Add(1) go func(id int) { for i := 0; i < 1000; i++ { - _, vals, err := GetParamSQLFromAST(context.Background(), MockContext(), stmts[id]) + _, vals, err := GetParamSQLFromAST(MockContext(), stmts[id]) require.Nil(t, err) require.Equal(t, len(vals), 3) require.Equal(t, vals[0].GetValue(), int64(id*3+0)) @@ -159,13 +157,12 @@ func BenchmarkParameterizeSelect(b *testing.B) { c_credit, c_credit_lim, c_discount, c_balance, c_since FROM customer WHERE c_w_id = ? AND c_d_id = ?AND c_id = ? FOR UPDATE` stmt, err := parser.New().ParseOneStmt(paymentSelectCustomerForUpdate, "", "") require.Nil(b, err) - sctx := MockContext() - _, _, err = ParameterizeAST(context.Background(), sctx, stmt) + _, _, err = ParameterizeAST(stmt) require.Nil(b, err) b.ResetTimer() for i := 0; i < b.N; i++ { - ParameterizeAST(context.Background(), sctx, stmt) + ParameterizeAST(stmt) } } @@ -173,13 +170,12 @@ func BenchmarkParameterizeInsert(b *testing.B) { paymentInsertHistory := `INSERT INTO history (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data) VALUES (1, 2, 3, 4, 5, 6, 7, 8)` stmt, err := parser.New().ParseOneStmt(paymentInsertHistory, "", "") require.Nil(b, err) - sctx := MockContext() - _, _, err = ParameterizeAST(context.Background(), sctx, stmt) + _, _, err = ParameterizeAST(stmt) require.Nil(b, err) b.ResetTimer() for i := 0; i < b.N; i++ { - ParameterizeAST(context.Background(), sctx, stmt) + ParameterizeAST(stmt) } } @@ -191,6 +187,6 @@ func BenchmarkGetParamSQL(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - GetParamSQLFromAST(context.Background(), sctx, stmt) + GetParamSQLFromAST(sctx, stmt) } } diff --git a/planner/core/plan_cost_ver1.go b/planner/core/plan_cost_ver1.go index 8c5300574116b..156ac820837f9 100644 --- a/planner/core/plan_cost_ver1.go +++ b/planner/core/plan_cost_ver1.go @@ -172,7 +172,7 @@ func (p *PhysicalIndexLookUpReader) GetCost(costFlag uint64) (cost float64) { } // getPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost. -func (p *PhysicalIndexLookUpReader) getPlanCostVer1(taskType property.TaskType, option *PlanCostOption) (float64, error) { +func (p *PhysicalIndexLookUpReader) getPlanCostVer1(_ property.TaskType, option *PlanCostOption) (float64, error) { costFlag := option.CostFlag if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) { return p.planCost, nil @@ -190,8 +190,9 @@ func (p *PhysicalIndexLookUpReader) getPlanCostVer1(taskType property.TaskType, // to keep compatible with the previous cost implementation, re-calculate table-scan cost by using index stats-count again (see copTask.finishIndexPlan). // TODO: amend table-side cost here later - var tmp PhysicalPlan - for tmp = p.tablePlan; len(tmp.Children()) > 0; tmp = tmp.Children()[0] { + var tmp = p.tablePlan + for len(tmp.Children()) > 0 { + tmp = tmp.Children()[0] } ts := tmp.(*PhysicalTableScan) tblCost, err := ts.getPlanCostVer1(property.CopMultiReadTaskType, option) @@ -226,7 +227,7 @@ func (p *PhysicalIndexLookUpReader) getPlanCostVer1(taskType property.TaskType, } // getPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost. -func (p *PhysicalIndexReader) getPlanCostVer1(taskType property.TaskType, option *PlanCostOption) (float64, error) { +func (p *PhysicalIndexReader) getPlanCostVer1(_ property.TaskType, option *PlanCostOption) (float64, error) { costFlag := option.CostFlag if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) { return p.planCost, nil @@ -268,7 +269,7 @@ func (p *PhysicalIndexReader) GetNetDataSize() float64 { } // getPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost. -func (p *PhysicalTableReader) getPlanCostVer1(taskType property.TaskType, option *PlanCostOption) (float64, error) { +func (p *PhysicalTableReader) getPlanCostVer1(_ property.TaskType, option *PlanCostOption) (float64, error) { costFlag := option.CostFlag if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) { return p.planCost, nil @@ -351,7 +352,7 @@ func (p *PhysicalTableReader) GetNetDataSize() float64 { } // getPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost. -func (p *PhysicalIndexMergeReader) getPlanCostVer1(taskType property.TaskType, option *PlanCostOption) (float64, error) { +func (p *PhysicalIndexMergeReader) getPlanCostVer1(_ property.TaskType, option *PlanCostOption) (float64, error) { costFlag := option.CostFlag if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) { return p.planCost, nil @@ -405,7 +406,7 @@ func (p *PhysicalIndexMergeReader) GetPartialReaderNetDataSize(plan PhysicalPlan } // getPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost. -func (p *PhysicalTableScan) getPlanCostVer1(taskType property.TaskType, option *PlanCostOption) (float64, error) { +func (p *PhysicalTableScan) getPlanCostVer1(_ property.TaskType, option *PlanCostOption) (float64, error) { costFlag := option.CostFlag if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) { return p.planCost, nil @@ -430,7 +431,7 @@ func (p *PhysicalTableScan) getPlanCostVer1(taskType property.TaskType, option * } // getPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost. -func (p *PhysicalIndexScan) getPlanCostVer1(taskType property.TaskType, option *PlanCostOption) (float64, error) { +func (p *PhysicalIndexScan) getPlanCostVer1(_ property.TaskType, option *PlanCostOption) (float64, error) { costFlag := option.CostFlag if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) { return p.planCost, nil @@ -816,8 +817,8 @@ func (p *PhysicalMergeJoin) GetCost(lCnt, rCnt float64, costFlag uint64) float64 cpuCost += probeCost // For merge join, only one group of rows with same join key(not null) are cached, // we compute average memory cost using estimated group size. - NDV, _ := getColsNDVWithMatchedLen(innerKeys, innerSchema, innerStats) - memoryCost := (innerCnt / NDV) * sessVars.GetMemoryFactor() + ndv, _ := getColsNDVWithMatchedLen(innerKeys, innerSchema, innerStats) + memoryCost := (innerCnt / ndv) * sessVars.GetMemoryFactor() return cpuCost + memoryCost } @@ -841,7 +842,7 @@ func (p *PhysicalMergeJoin) getPlanCostVer1(taskType property.TaskType, option * } // GetCost computes cost of hash join operator itself. -func (p *PhysicalHashJoin) GetCost(lCnt, rCnt float64, isMPP bool, costFlag uint64, op *physicalOptimizeOp) float64 { +func (p *PhysicalHashJoin) GetCost(lCnt, rCnt float64, _ bool, costFlag uint64, op *physicalOptimizeOp) float64 { buildCnt, probeCnt := lCnt, rCnt build := p.children[0] // Taking the right as the inner for right join or using the outer to build a hash table. @@ -957,7 +958,7 @@ func (p *PhysicalHashJoin) getPlanCostVer1(taskType property.TaskType, option *P } // GetCost computes cost of stream aggregation considering CPU/memory. -func (p *PhysicalStreamAgg) GetCost(inputRows float64, isRoot, isMPP bool, costFlag uint64) float64 { +func (p *PhysicalStreamAgg) GetCost(inputRows float64, isRoot, _ bool, costFlag uint64) float64 { aggFuncFactor := p.getAggFuncCostFactor(false) var cpuCost float64 sessVars := p.ctx.GetSessionVars() @@ -1144,7 +1145,7 @@ func (p *BatchPointGetPlan) GetCost(opt *physicalOptimizeOp) float64 { } // getPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost. -func (p *BatchPointGetPlan) getPlanCostVer1(taskType property.TaskType, option *PlanCostOption) (float64, error) { +func (p *BatchPointGetPlan) getPlanCostVer1(_ property.TaskType, option *PlanCostOption) (float64, error) { costFlag := option.CostFlag if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) { return p.planCost, nil @@ -1192,7 +1193,7 @@ func (p *PointGetPlan) GetCost(opt *physicalOptimizeOp) float64 { } // getPlanCostVer1 calculates the cost of the plan if it has not been calculated yet and returns the cost. -func (p *PointGetPlan) getPlanCostVer1(taskType property.TaskType, option *PlanCostOption) (float64, error) { +func (p *PointGetPlan) getPlanCostVer1(_ property.TaskType, option *PlanCostOption) (float64, error) { costFlag := option.CostFlag if p.planCostInit && !hasCostFlag(costFlag, CostFlagRecalculate) { return p.planCost, nil diff --git a/planner/core/rule_join_reorder_dp.go b/planner/core/rule_join_reorder_dp.go index dc13c59633146..9e87ced883fe3 100644 --- a/planner/core/rule_join_reorder_dp.go +++ b/planner/core/rule_join_reorder_dp.go @@ -138,7 +138,7 @@ func (s *joinReorderDPSolver) solve(joinGroup []LogicalPlan, tracer *joinReorder } // bfsGraph bfs a sub graph starting at startPos. And relabel its label for future use. -func (s *joinReorderDPSolver) bfsGraph(startNode int, visited []bool, adjacents [][]int, nodeID2VisitID []int) []int { +func (*joinReorderDPSolver) bfsGraph(startNode int, visited []bool, adjacents [][]int, nodeID2VisitID []int) []int { queue := []int{startNode} visited[startNode] = true var visitID2NodeID []int @@ -211,7 +211,7 @@ func (s *joinReorderDPSolver) dpGraph(visitID2NodeID, nodeID2VisitID []int, _ [] return bestPlan[(1< newStart { s = start } else { @@ -1268,7 +1265,7 @@ type rangePruner struct { monotonous monotoneMode } -func (p *rangePruner) partitionRangeForExpr(sctx sessionctx.Context, expr expression.Expression) (int, int, bool) { +func (p *rangePruner) partitionRangeForExpr(sctx sessionctx.Context, expr expression.Expression) (start int, end int, ok bool) { if constExpr, ok := expr.(*expression.Constant); ok { if b, err := constExpr.Value.ToBool(sctx.GetSessionVars().StmtCtx); err == nil && b == 0 { // A constant false expression. @@ -1282,7 +1279,7 @@ func (p *rangePruner) partitionRangeForExpr(sctx sessionctx.Context, expr expres } unsigned := mysql.HasUnsignedFlag(p.col.RetType.GetFlag()) - start, end := pruneUseBinarySearch(p.lessThan, dataForPrune, unsigned) + start, end = pruneUseBinarySearch(p.lessThan, dataForPrune, unsigned) return start, end, true } @@ -1586,7 +1583,7 @@ func pruneUseBinarySearch(lessThan lessThanDataInt, data dataForPrune, unsigned return start, end } -func (s *partitionProcessor) resolveAccessPaths(ds *DataSource) error { +func (*partitionProcessor) resolveAccessPaths(ds *DataSource) error { possiblePaths, err := getPossibleAccessPaths( ds.ctx, &tableHintInfo{indexMergeHintList: ds.indexMergeHints, indexHintList: ds.IndexHints}, ds.astIndexHints, ds.table, ds.DBName, ds.tableInfo.Name, ds.isForUpdateRead, true) @@ -1686,7 +1683,7 @@ func appendWarnForUnknownPartitions(ctx sessionctx.Context, hintName string, unk ctx.GetSessionVars().StmtCtx.AppendWarning(warning) } -func (s *partitionProcessor) checkHintsApplicable(ds *DataSource, partitionSet set.StringSet) { +func (*partitionProcessor) checkHintsApplicable(ds *DataSource, partitionSet set.StringSet) { for _, idxHint := range ds.IndexHints { unknownPartitions := checkTableHintsApplicableForPartition(idxHint.partitions, partitionSet) appendWarnForUnknownPartitions(ds.ctx, restore2IndexHint(idxHint.hintTypeString(), idxHint), unknownPartitions) @@ -1756,7 +1753,7 @@ func (s *partitionProcessor) makeUnionAllChildren(ds *DataSource, pi *model.Part return unionAll, nil } -func (s *partitionProcessor) pruneRangeColumnsPartition(ctx sessionctx.Context, conds []expression.Expression, pi *model.PartitionInfo, pe *tables.PartitionExpr, columns []*expression.Column) (partitionRangeOR, error) { +func (*partitionProcessor) pruneRangeColumnsPartition(ctx sessionctx.Context, conds []expression.Expression, pi *model.PartitionInfo, pe *tables.PartitionExpr, columns []*expression.Column) (partitionRangeOR, error) { result := fullRange(len(pi.Definitions)) if len(pi.Columns) < 1 { @@ -1816,7 +1813,7 @@ func (p *rangeColumnsPruner) getPartCol(colID int64) *expression.Column { return nil } -func (p *rangeColumnsPruner) partitionRangeForExpr(sctx sessionctx.Context, expr expression.Expression) (int, int, bool) { +func (p *rangeColumnsPruner) partitionRangeForExpr(sctx sessionctx.Context, expr expression.Expression) (start int, end int, ok bool) { op, ok := expr.(*expression.ScalarFunction) if !ok { return 0, len(p.lessThan), false @@ -1867,7 +1864,7 @@ func (p *rangeColumnsPruner) partitionRangeForExpr(sctx sessionctx.Context, expr if exprColl != colColl && (opName != ast.EQ || !collate.IsBinCollation(exprColl)) { return 0, len(p.lessThan), true } - start, end := p.pruneUseBinarySearch(sctx, opName, con) + start, end = p.pruneUseBinarySearch(sctx, opName, con) return start, end, true } diff --git a/planner/core/rule_predicate_push_down.go b/planner/core/rule_predicate_push_down.go index e3df3c6245f18..6e08aa65c91af 100644 --- a/planner/core/rule_predicate_push_down.go +++ b/planner/core/rule_predicate_push_down.go @@ -42,7 +42,7 @@ type exprPrefixAdder struct { lengths []int } -func (s *ppdSolver) optimize(_ context.Context, lp LogicalPlan, opt *logicalOptimizeOp) (LogicalPlan, error) { +func (*ppdSolver) optimize(_ context.Context, lp LogicalPlan, opt *logicalOptimizeOp) (LogicalPlan, error) { _, p := lp.PredicatePushDown(nil, opt) return p, nil } @@ -896,17 +896,17 @@ func (ds *DataSource) AddPrefix4ShardIndexes(sc sessionctx.Context, conds []expr func (ds *DataSource) addExprPrefixCond(sc sessionctx.Context, path *util.AccessPath, conds []expression.Expression) ([]expression.Expression, error) { - IdxCols, IdxColLens := + idxCols, idxColLens := expression.IndexInfo2PrefixCols(ds.Columns, ds.schema.Columns, path.Index) - if len(IdxCols) == 0 { + if len(idxCols) == 0 { return conds, nil } adder := &exprPrefixAdder{ sctx: sc, OrigConds: conds, - cols: IdxCols, - lengths: IdxColLens, + cols: idxCols, + lengths: idxColLens, } return adder.addExprPrefix4ShardIndex() diff --git a/planner/core/rule_predicate_simplification.go b/planner/core/rule_predicate_simplification.go index 87231ccd35fa0..403b212885fcc 100644 --- a/planner/core/rule_predicate_simplification.go +++ b/planner/core/rule_predicate_simplification.go @@ -65,7 +65,7 @@ func findPredicateType(expr expression.Expression) (*expression.Column, predicat return nil, otherPredicate } -func (s *predicateSimplification) optimize(_ context.Context, p LogicalPlan, opt *logicalOptimizeOp) (LogicalPlan, error) { +func (*predicateSimplification) optimize(_ context.Context, p LogicalPlan, opt *logicalOptimizeOp) (LogicalPlan, error) { return p.predicateSimplification(opt), nil } @@ -154,8 +154,8 @@ func applyPredicateSimplification(sctx sessionctx.Context, predicates []expressi return newValues } -func (s *DataSource) predicateSimplification(opt *logicalOptimizeOp) LogicalPlan { - p := s.self.(*DataSource) +func (ds *DataSource) predicateSimplification(*logicalOptimizeOp) LogicalPlan { + p := ds.self.(*DataSource) p.pushedDownConds = applyPredicateSimplification(p.ctx, p.pushedDownConds) p.allConds = applyPredicateSimplification(p.ctx, p.allConds) return p diff --git a/planner/core/rule_result_reorder.go b/planner/core/rule_result_reorder.go index a182501cc05e1..afb17b487d123 100644 --- a/planner/core/rule_result_reorder.go +++ b/planner/core/rule_result_reorder.go @@ -93,7 +93,7 @@ func (rs *resultReorder) injectSort(lp LogicalPlan) LogicalPlan { return sort } -func (rs *resultReorder) isInputOrderKeeper(lp LogicalPlan) bool { +func (*resultReorder) isInputOrderKeeper(lp LogicalPlan) bool { switch lp.(type) { case *LogicalSelection, *LogicalProjection, *LogicalLimit: return true @@ -123,6 +123,6 @@ func (rs *resultReorder) extractHandleCol(lp LogicalPlan) *expression.Column { return nil } -func (rs *resultReorder) name() string { +func (*resultReorder) name() string { return "result_reorder" } diff --git a/planner/optimize.go b/planner/optimize.go index 6312b3681ed50..26e0b34a31ce3 100644 --- a/planner/optimize.go +++ b/planner/optimize.go @@ -97,7 +97,7 @@ func getPlanFromNonPreparedPlanCache(ctx context.Context, sctx sessionctx.Contex return nil, nil, false, nil } - paramSQL, paramsVals, err := core.GetParamSQLFromAST(ctx, sctx, stmt) + paramSQL, paramsVals, err := core.GetParamSQLFromAST(sctx, stmt) if err != nil { return nil, nil, false, err }