From 7279c94ac160aee516b2d2902e60df88307009f1 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Fri, 4 Aug 2023 16:44:48 +0800 Subject: [PATCH 1/3] planner: don't force set the Column in physical proj elimination --- planner/core/rule_eliminate_projection.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/planner/core/rule_eliminate_projection.go b/planner/core/rule_eliminate_projection.go index d744092ae7968..5943f74fd70b5 100644 --- a/planner/core/rule_eliminate_projection.go +++ b/planner/core/rule_eliminate_projection.go @@ -152,16 +152,7 @@ func eliminatePhysicalProjection(p PhysicalPlan) PhysicalPlan { } }) - oldSchema := p.Schema() newRoot := doPhysicalProjectionElimination(p) - newCols := newRoot.Schema().Columns - for i, oldCol := range oldSchema.Columns { - oldCol.Index = newCols[i].Index - oldCol.ID = newCols[i].ID - oldCol.UniqueID = newCols[i].UniqueID - oldCol.VirtualExpr = newCols[i].VirtualExpr - newRoot.Schema().Columns[i] = oldCol - } return newRoot } From b86ecdd81337517a6b657ca8278c495e986d7a99 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Tue, 15 Aug 2023 21:01:25 +0800 Subject: [PATCH 2/3] use logical's stats to avoid the col ID's change --- planner/core/stats.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/stats.go b/planner/core/stats.go index 04e99339d1928..d81aa849bba28 100644 --- a/planner/core/stats.go +++ b/planner/core/stats.go @@ -1135,7 +1135,7 @@ func (p *LogicalCTE) DeriveStats(_ []*property.StatsInfo, selfSchema *expression return nil, err } } - recurStat := p.cte.recursivePartPhysicalPlan.StatsInfo() + recurStat := p.cte.recursivePartLogicalPlan.StatsInfo() for i, col := range selfSchema.Columns { p.StatsInfo().ColNDVs[col.UniqueID] += recurStat.ColNDVs[p.cte.recursivePartLogicalPlan.Schema().Columns[i].UniqueID] } From 229152deb4245019fffc175041e9a128a8825253 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Tue, 15 Aug 2023 21:34:46 +0800 Subject: [PATCH 3/3] fix physical plan test --- .../casetest/physicalplantest/testdata/plan_suite_out.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json b/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json index f76dedf97f2b8..81bfeb94723dd 100644 --- a/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json +++ b/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json @@ -3905,8 +3905,8 @@ { "SQL": "with recursive cte(a) as (select 1 union select a from cte) select * from cte; -- recursive cte cannot be inlined", "Plan": [ - "CTEFullScan 1.00 root CTE:cte data:CTE_0", - "CTE_0 1.00 root Recursive CTE", + "CTEFullScan 2.00 root CTE:cte data:CTE_0", + "CTE_0 2.00 root Recursive CTE", "├─Projection(Seed Part) 1.00 root 1->Column#2", "│ └─TableDual 1.00 root rows:1", "└─CTETable(Recursive Part) 1.00 root Scan on CTE_0"