From b70a163b31d7490783af64614dead2c73c5a2651 Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Wed, 16 Aug 2023 11:51:30 +0900 Subject: [PATCH 1/2] This is an automated cherry-pick of #45824 Signed-off-by: ti-chi-bot --- planner/core/casetest/testdata/plan_suite_out.json | 4 ++-- planner/core/rule_eliminate_projection.go | 9 --------- planner/core/stats.go | 4 ++++ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/planner/core/casetest/testdata/plan_suite_out.json b/planner/core/casetest/testdata/plan_suite_out.json index 212a56c7375a4..8fda11bb0f3a6 100644 --- a/planner/core/casetest/testdata/plan_suite_out.json +++ b/planner/core/casetest/testdata/plan_suite_out.json @@ -3850,8 +3850,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" diff --git a/planner/core/rule_eliminate_projection.go b/planner/core/rule_eliminate_projection.go index 83936e7cd9e94..1459896f30b01 100644 --- a/planner/core/rule_eliminate_projection.go +++ b/planner/core/rule_eliminate_projection.go @@ -144,16 +144,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 } diff --git a/planner/core/stats.go b/planner/core/stats.go index 83d423c531aa1..74378ca03d35f 100644 --- a/planner/core/stats.go +++ b/planner/core/stats.go @@ -1131,7 +1131,11 @@ func (p *LogicalCTE) DeriveStats(_ []*property.StatsInfo, selfSchema *expression return nil, err } } +<<<<<<< HEAD recurStat := p.cte.recursivePartPhysicalPlan.Stats() +======= + recurStat := p.cte.recursivePartLogicalPlan.StatsInfo() +>>>>>>> 0fb21c50580 (planner: don't force set the Column in physical proj elimination (#45824)) for i, col := range selfSchema.Columns { p.stats.ColNDVs[col.UniqueID] += recurStat.ColNDVs[p.cte.recursivePartLogicalPlan.Schema().Columns[i].UniqueID] } From 9a7f4c19f8085128194015b946a97753904b1191 Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Thu, 24 Aug 2023 14:36:02 +0800 Subject: [PATCH 2/2] Update stats.go --- planner/core/stats.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/planner/core/stats.go b/planner/core/stats.go index 74378ca03d35f..71d0d5a36af40 100644 --- a/planner/core/stats.go +++ b/planner/core/stats.go @@ -1131,11 +1131,7 @@ func (p *LogicalCTE) DeriveStats(_ []*property.StatsInfo, selfSchema *expression return nil, err } } -<<<<<<< HEAD - recurStat := p.cte.recursivePartPhysicalPlan.Stats() -======= - recurStat := p.cte.recursivePartLogicalPlan.StatsInfo() ->>>>>>> 0fb21c50580 (planner: don't force set the Column in physical proj elimination (#45824)) + recurStat := p.cte.recursivePartLogicalPlan.statsInfo() for i, col := range selfSchema.Columns { p.stats.ColNDVs[col.UniqueID] += recurStat.ColNDVs[p.cte.recursivePartLogicalPlan.Schema().Columns[i].UniqueID] }