Skip to content

Commit 9561895

Browse files
committed
copilot review comments2
1 parent 59654e8 commit 9561895

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pkg/planner/core/logical_plan_builder.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4510,6 +4510,9 @@ func (b *PlanBuilder) tryBuildCTE(ctx context.Context, tn *ast.TableName, asName
45104510
}
45114511
var p base.LogicalPlan
45124512
lp := logicalop.LogicalCTE{CteAsName: tn.Name, CteName: tn.Name, Cte: cte.cteClass, SeedStat: cte.seedStat}.Init(b.ctx, b.getSelectOffset())
4513+
// Use cteClass.SeedPartLogicalPlan.Schema() (not cte.seedLP.Schema()) to ensure all references
4514+
// to the same CTE use a consistent schema. When a CTE is referenced multiple times, cteClass
4515+
// is shared and contains the schema from when the CTE was first processed.
45134516
prevSchema := cte.cteClass.SeedPartLogicalPlan.Schema().Clone()
45144517
lp.SetSchema(getResultCTESchema(cte.cteClass.SeedPartLogicalPlan.Schema(), b.ctx.GetSessionVars()))
45154518

0 commit comments

Comments
 (0)