From f1fca6a8b4074360b55a3807c101aaaf3e610f8c Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 8 Jan 2025 12:35:27 +0800 Subject: [PATCH 1/3] planner: prealloc the slices in the SplitCorColAccessCondFromFilters Signed-off-by: Weizhen Wang --- pkg/planner/util/path.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/planner/util/path.go b/pkg/planner/util/path.go index a8ccf7df379f2..37d3e56b24567 100644 --- a/pkg/planner/util/path.go +++ b/pkg/planner/util/path.go @@ -194,6 +194,7 @@ func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx planctx.PlanContext } access = make([]expression.Expression, len(path.IdxCols)-eqOrInCount) used := make([]bool, len(path.TableFilters)) + remainedCnt := 0 for i := eqOrInCount; i < len(path.IdxCols); i++ { matched := false for j, filter := range path.TableFilters { @@ -217,6 +218,7 @@ func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx planctx.PlanContext access[i-eqOrInCount] = filter if path.IdxColLens[i] == types.UnspecifiedLength { used[j] = true + remainedCnt++ } break } @@ -225,6 +227,7 @@ func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx planctx.PlanContext break } } + remained = make([]expression.Expression, len(used)-remainedCnt) for i, ok := range used { if !ok { remained = append(remained, path.TableFilters[i]) // nozero From a009197276ef51ddc64099d5c81fed067190aafb Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 8 Jan 2025 12:48:03 +0800 Subject: [PATCH 2/3] update Signed-off-by: Weizhen Wang --- pkg/planner/util/path.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/planner/util/path.go b/pkg/planner/util/path.go index 37d3e56b24567..ea62c531669c6 100644 --- a/pkg/planner/util/path.go +++ b/pkg/planner/util/path.go @@ -227,7 +227,7 @@ func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx planctx.PlanContext break } } - remained = make([]expression.Expression, len(used)-remainedCnt) + remained = make([]expression.Expression, 0, len(used)-remainedCnt) for i, ok := range used { if !ok { remained = append(remained, path.TableFilters[i]) // nozero From 19a9c943e9bcf5679f4b0aecefb2f8f8fda28225 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 8 Jan 2025 14:48:16 +0800 Subject: [PATCH 3/3] update Signed-off-by: Weizhen Wang --- pkg/planner/util/path.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/planner/util/path.go b/pkg/planner/util/path.go index ea62c531669c6..2aba097c4086a 100644 --- a/pkg/planner/util/path.go +++ b/pkg/planner/util/path.go @@ -194,7 +194,7 @@ func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx planctx.PlanContext } access = make([]expression.Expression, len(path.IdxCols)-eqOrInCount) used := make([]bool, len(path.TableFilters)) - remainedCnt := 0 + usedCnt := 0 for i := eqOrInCount; i < len(path.IdxCols); i++ { matched := false for j, filter := range path.TableFilters { @@ -218,7 +218,7 @@ func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx planctx.PlanContext access[i-eqOrInCount] = filter if path.IdxColLens[i] == types.UnspecifiedLength { used[j] = true - remainedCnt++ + usedCnt++ } break } @@ -227,7 +227,7 @@ func (path *AccessPath) SplitCorColAccessCondFromFilters(ctx planctx.PlanContext break } } - remained = make([]expression.Expression, 0, len(used)-remainedCnt) + remained = make([]expression.Expression, 0, len(used)-usedCnt) for i, ok := range used { if !ok { remained = append(remained, path.TableFilters[i]) // nozero