From 17e43e06c55a5753f063666667f89d6cd0d05e60 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 8 Jan 2025 18:18:26 +0800 Subject: [PATCH 1/3] planner: remove skip prealloc tag Signed-off-by: Weizhen Wang --- pkg/planner/core/operator/logicalop/logical_aggregation.go | 2 -- pkg/planner/core/rule_join_reorder.go | 3 +-- pkg/planner/core/rule_join_reorder_dp.go | 2 -- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_aggregation.go b/pkg/planner/core/operator/logicalop/logical_aggregation.go index 88968dba476ef..3d9ca6af06990 100644 --- a/pkg/planner/core/operator/logicalop/logical_aggregation.go +++ b/pkg/planner/core/operator/logicalop/logical_aggregation.go @@ -135,7 +135,6 @@ func (la *LogicalAggregation) PruneColumns(parentUsedCols []*expression.Column, } logicaltrace.AppendColumnPruneTraceStep(la, prunedColumns, opt) logicaltrace.AppendFunctionPruneTraceStep(la, prunedFunctions, opt) - //nolint: prealloc var selfUsedCols []*expression.Column for _, aggrFunc := range la.AggFuncs { selfUsedCols = expression.ExtractColumnsFromExpressions(selfUsedCols, aggrFunc.Args, nil) @@ -597,7 +596,6 @@ func (la *LogicalAggregation) pushDownCNFPredicatesForAggregation(cond expressio // (a > 1 and avg(b) > 1) or (a < 3), and `avg(b) > 1` can't be pushed-down. // Then condsToPush: (a < 3) and (a > 1), ret: (a > 1 and avg(b) > 1) or (a < 3) func (la *LogicalAggregation) pushDownDNFPredicatesForAggregation(cond expression.Expression, groupByColumns *expression.Schema, exprsOriginal []expression.Expression) ([]expression.Expression, []expression.Expression) { - //nolint: prealloc var condsToPush []expression.Expression var ret []expression.Expression subDNFItem := expression.SplitDNFItems(cond) diff --git a/pkg/planner/core/rule_join_reorder.go b/pkg/planner/core/rule_join_reorder.go index 1bd970609dff3..81dc479b560f0 100644 --- a/pkg/planner/core/rule_join_reorder.go +++ b/pkg/planner/core/rule_join_reorder.go @@ -796,8 +796,7 @@ func findRoots(t *tracing.PlanTrace) []*tracing.PlanTrace { if t.TP == plancodec.TypeJoin || t.TP == plancodec.TypeDataSource { return []*tracing.PlanTrace{t} } - //nolint: prealloc - var r []*tracing.PlanTrace + r := make([]*tracing.PlanTrace, 0, 5) for _, child := range t.Children { r = append(r, findRoots(child)...) } diff --git a/pkg/planner/core/rule_join_reorder_dp.go b/pkg/planner/core/rule_join_reorder_dp.go index 804a5714f88fd..c419c7f569920 100644 --- a/pkg/planner/core/rule_join_reorder_dp.go +++ b/pkg/planner/core/rule_join_reorder_dp.go @@ -216,9 +216,7 @@ func (s *joinReorderDPSolver) dpGraph(visitID2NodeID, nodeID2VisitID []int, _ [] func (*joinReorderDPSolver) nodesAreConnected(leftMask, rightMask uint, oldPos2NewPos []int, totalEqEdges []joinGroupEqEdge, totalNonEqEdges []joinGroupNonEqEdge) ([]joinGroupEqEdge, []expression.Expression) { - //nolint: prealloc var usedEqEdges []joinGroupEqEdge - //nolint: prealloc var otherConds []expression.Expression for _, edge := range totalEqEdges { From 8d3b1780b01d3c30053d430bb05144dd81c7a0e5 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 8 Jan 2025 18:26:49 +0800 Subject: [PATCH 2/3] planner: remove skip prealloc tag Signed-off-by: Weizhen Wang --- pkg/planner/core/operator/logicalop/logical_aggregation.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/planner/core/operator/logicalop/logical_aggregation.go b/pkg/planner/core/operator/logicalop/logical_aggregation.go index 3d9ca6af06990..391784a5205c3 100644 --- a/pkg/planner/core/operator/logicalop/logical_aggregation.go +++ b/pkg/planner/core/operator/logicalop/logical_aggregation.go @@ -135,7 +135,7 @@ func (la *LogicalAggregation) PruneColumns(parentUsedCols []*expression.Column, } logicaltrace.AppendColumnPruneTraceStep(la, prunedColumns, opt) logicaltrace.AppendFunctionPruneTraceStep(la, prunedFunctions, opt) - var selfUsedCols []*expression.Column + selfUsedCols := make([]*expression.Column, 0, 5) for _, aggrFunc := range la.AggFuncs { selfUsedCols = expression.ExtractColumnsFromExpressions(selfUsedCols, aggrFunc.Args, nil) @@ -596,12 +596,12 @@ func (la *LogicalAggregation) pushDownCNFPredicatesForAggregation(cond expressio // (a > 1 and avg(b) > 1) or (a < 3), and `avg(b) > 1` can't be pushed-down. // Then condsToPush: (a < 3) and (a > 1), ret: (a > 1 and avg(b) > 1) or (a < 3) func (la *LogicalAggregation) pushDownDNFPredicatesForAggregation(cond expression.Expression, groupByColumns *expression.Schema, exprsOriginal []expression.Expression) ([]expression.Expression, []expression.Expression) { - var condsToPush []expression.Expression - var ret []expression.Expression subDNFItem := expression.SplitDNFItems(cond) if len(subDNFItem) == 1 { return la.pushDownPredicatesForAggregation(subDNFItem[0], groupByColumns, exprsOriginal) } + condsToPush := make([]expression.Expression, 0, len(subDNFItem)) + var ret []expression.Expression exprCtx := la.SCtx().GetExprCtx() for _, item := range subDNFItem { condsToPushForItem, retForItem := la.pushDownCNFPredicatesForAggregation(item, groupByColumns, exprsOriginal) From d66b2c81f29f06f2d8884cd90c5012a37d06e2dc Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 8 Jan 2025 18:37:25 +0800 Subject: [PATCH 3/3] planner: remove skip prealloc tag Signed-off-by: Weizhen Wang --- pkg/planner/core/rule_join_reorder_dp.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/planner/core/rule_join_reorder_dp.go b/pkg/planner/core/rule_join_reorder_dp.go index c419c7f569920..860e7d7ee6d32 100644 --- a/pkg/planner/core/rule_join_reorder_dp.go +++ b/pkg/planner/core/rule_join_reorder_dp.go @@ -217,8 +217,6 @@ func (s *joinReorderDPSolver) dpGraph(visitID2NodeID, nodeID2VisitID []int, _ [] func (*joinReorderDPSolver) nodesAreConnected(leftMask, rightMask uint, oldPos2NewPos []int, totalEqEdges []joinGroupEqEdge, totalNonEqEdges []joinGroupNonEqEdge) ([]joinGroupEqEdge, []expression.Expression) { var usedEqEdges []joinGroupEqEdge - var otherConds []expression.Expression - for _, edge := range totalEqEdges { lIdx := uint(oldPos2NewPos[edge.nodeIDs[0]]) rIdx := uint(oldPos2NewPos[edge.nodeIDs[1]]) @@ -226,6 +224,7 @@ func (*joinReorderDPSolver) nodesAreConnected(leftMask, rightMask uint, oldPos2N usedEqEdges = append(usedEqEdges, edge) } } + otherConds := make([]expression.Expression, 0, len(totalNonEqEdges)) for _, edge := range totalNonEqEdges { // If the result is false, means that the current group hasn't covered the columns involved in the expression. if edge.nodeIDMask&(leftMask|rightMask) != edge.nodeIDMask {