From 6f4dd17216ce4cb161ad8f2b7a96acdd4af2f6af Mon Sep 17 00:00:00 2001 From: ti-srebot <66930949+ti-srebot@users.noreply.github.com> Date: Fri, 13 Aug 2021 17:55:59 +0800 Subject: [PATCH] planner: Fix the problem that `PlanBuilder.buildWindowFunctions` may change sub operator's schema. (#27176) (#27204) --- expression/aggregation/base_func.go | 2 +- planner/core/logical_plan_builder.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/expression/aggregation/base_func.go b/expression/aggregation/base_func.go index 1a1a7543ef29a..64dbcd2e88689 100644 --- a/expression/aggregation/base_func.go +++ b/expression/aggregation/base_func.go @@ -432,7 +432,7 @@ func (a *baseFuncDesc) WrapCastForAggArgs(ctx sessionctx.Context) { if col, ok := a.Args[i].(*expression.Column); ok { col.RetType = types.NewFieldType(col.RetType.Tp) } - // originTp is used when the the `Tp` of column is TypeFloat32 while + // originTp is used when the `Tp` of column is TypeFloat32 while // the type of the aggregation function is TypeFloat64. originTp := a.Args[i].GetType().Tp *(a.Args[i].GetType()) = *(a.RetTp) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 76566d93ac61a..0d2aecf3f0083 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -4511,7 +4511,7 @@ func (b *PlanBuilder) buildProjectionForWindow(ctx context.Context, p LogicalPla p = np switch newArg.(type) { case *expression.Column, *expression.Constant: - newArgList = append(newArgList, newArg) + newArgList = append(newArgList, newArg.Clone()) continue } proj.Exprs = append(proj.Exprs, newArg) @@ -4543,7 +4543,7 @@ func (b *PlanBuilder) buildArgs4WindowFunc(ctx context.Context, p LogicalPlan, a p = np switch newArg.(type) { case *expression.Column, *expression.Constant: - newArgList = append(newArgList, newArg) + newArgList = append(newArgList, newArg.Clone()) continue } col := &expression.Column{