From 76d05e86acf4cffe6ce3905b5f3856d3ecf2514d Mon Sep 17 00:00:00 2001 From: AilinKid <314806019@qq.com> Date: Fri, 17 Nov 2023 17:04:19 +0800 Subject: [PATCH] fix potential modification of shared immutable aggDesc Signed-off-by: AilinKid <314806019@qq.com> --- planner/core/physical_plans.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/planner/core/physical_plans.go b/planner/core/physical_plans.go index 195f746976860..ee4a226e6c2e5 100644 --- a/planner/core/physical_plans.go +++ b/planner/core/physical_plans.go @@ -1163,10 +1163,20 @@ func (p *PhysicalHashAgg) Clone() (PhysicalPlan, error) { // NewPhysicalHashAgg creates a new PhysicalHashAgg from a LogicalAggregation. func NewPhysicalHashAgg(la *LogicalAggregation, newStats *property.StatsInfo, prop *property.PhysicalProperty) *PhysicalHashAgg { + newGbyItems := make([]expression.Expression, len(la.GroupByItems)) + copy(newGbyItems, la.GroupByItems) + newAggFuncs := make([]*aggregation.AggFuncDesc, len(la.AggFuncs)) + // There's some places that rewrites the aggFunc in-place. + // I clone it first. + // It needs a well refactor to make sure that the physical optimize should not change the things of logical plan. + // It's bad for cascades + for i, aggFunc := range la.AggFuncs { + newAggFuncs[i] = aggFunc.Clone() + } agg := basePhysicalAgg{ - GroupByItems: la.GroupByItems, - AggFuncs: la.AggFuncs, - }.initForHash(la.ctx, newStats, la.blockOffset, prop) + GroupByItems: newGbyItems, + AggFuncs: newAggFuncs, + }.initForHash(la.SCtx(), newStats, la.SelectBlockOffset(), prop) return agg }