From e7857b063145e943bbe3089549a18acf0fcc0708 Mon Sep 17 00:00:00 2001 From: Kenan Yao Date: Mon, 15 Jul 2019 16:27:31 +0800 Subject: [PATCH] planner: disable projection elimination for select plan of update (#10962) --- planner/core/cbo_test.go | 15 +++++++++++++++ planner/core/logical_plan_builder.go | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/planner/core/cbo_test.go b/planner/core/cbo_test.go index d15112ada3956..c212258eaf1a3 100644 --- a/planner/core/cbo_test.go +++ b/planner/core/cbo_test.go @@ -1091,3 +1091,18 @@ func (s *testAnalyzeSuite) TestLimitCrossEstimation(c *C) { " └─TableScan_19 6.00 cop table:t, keep order:false", )) } + +func (s *testAnalyzeSuite) TestUpdateProjEliminate(c *C) { + store, dom, err := newStoreWithBootstrap() + c.Assert(err, IsNil) + tk := testkit.NewTestKit(c, store) + defer func() { + dom.Close() + store.Close() + }() + + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, b int)") + tk.MustExec("explain update t t1, (select distinct b from t) t2 set t1.b = t2.b") +} diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index aef9c149234ee..ad79f4ce9c8ac 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -2587,7 +2587,9 @@ func (b *PlanBuilder) buildUpdate(update *ast.UpdateStmt) (Plan, error) { updt := Update{OrderedList: orderedList}.Init(b.ctx) updt.SetSchema(p.Schema()) - updt.SelectPlan, err = DoOptimize(b.optFlag, p) + // We cannot apply projection elimination when building the subplan, because + // columns in orderedList cannot be resolved. + updt.SelectPlan, err = DoOptimize(b.optFlag&^flagEliminateProjection, p) if err != nil { return nil, err }