From 64223f83dfb52ba03c1e0a5fd7725b1236526ff0 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Fri, 14 Feb 2025 17:08:56 +0800 Subject: [PATCH 1/2] expression: avoid slicesgrow in the PushDownExprsWithExtraInfo Signed-off-by: Weizhen Wang --- pkg/expression/infer_pushdown.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/expression/infer_pushdown.go b/pkg/expression/infer_pushdown.go index 937f70629371b..1a6a80da7bd3f 100644 --- a/pkg/expression/infer_pushdown.go +++ b/pkg/expression/infer_pushdown.go @@ -523,6 +523,8 @@ func (ctx PushDownContext) AppendWarning(err error) { // PushDownExprsWithExtraInfo split the input exprs into pushed and remained, pushed include all the exprs that can be pushed down func PushDownExprsWithExtraInfo(ctx PushDownContext, exprs []Expression, storeType kv.StoreType, canEnumPush bool) (pushed []Expression, remained []Expression) { + pushed = make([]Expression, 0, len(exprs)) + remained = make([]Expression, 0, len(exprs)) for _, expr := range exprs { if canExprPushDown(ctx, expr, storeType, canEnumPush) { pushed = append(pushed, expr) From 2678fdbb7299a54a31afa3ead18dec009a6e4c27 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 17 Feb 2025 18:21:19 +0800 Subject: [PATCH 2/2] update Signed-off-by: Weizhen Wang --- pkg/expression/infer_pushdown.go | 3 +++ pkg/planner/core/find_best_task.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/expression/infer_pushdown.go b/pkg/expression/infer_pushdown.go index 1a6a80da7bd3f..2837824128211 100644 --- a/pkg/expression/infer_pushdown.go +++ b/pkg/expression/infer_pushdown.go @@ -523,6 +523,9 @@ func (ctx PushDownContext) AppendWarning(err error) { // PushDownExprsWithExtraInfo split the input exprs into pushed and remained, pushed include all the exprs that can be pushed down func PushDownExprsWithExtraInfo(ctx PushDownContext, exprs []Expression, storeType kv.StoreType, canEnumPush bool) (pushed []Expression, remained []Expression) { + if len(exprs) == 0 { + return nil, nil + } pushed = make([]Expression, 0, len(exprs)) remained = make([]Expression, 0, len(exprs)) for _, expr := range exprs { diff --git a/pkg/planner/core/find_best_task.go b/pkg/planner/core/find_best_task.go index 0b46e84c7d6a1..d6570dc7eeb8d 100644 --- a/pkg/planner/core/find_best_task.go +++ b/pkg/planner/core/find_best_task.go @@ -2385,7 +2385,7 @@ func (is *PhysicalIndexScan) addPushedDownSelection(copTask *CopTask, p *logical return err } - if indexConds != nil { + if len(indexConds) != 0 { var selectivity float64 if path.CountAfterAccess > 0 { selectivity = path.CountAfterIndex / path.CountAfterAccess