Skip to content

Commit

Permalink
planner: disable projection elimination for select plan of update (pi…
Browse files Browse the repository at this point in the history
…ngcap#10962)

Conflicts:
	planner/core/cbo_test.go
	planner/core/logical_plan_builder.go
  • Loading branch information
eurekaka committed Jul 15, 2019
1 parent aeed234 commit 325bc16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions planner/core/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,3 +849,18 @@ func BenchmarkOptimize(b *testing.B) {
})
}
}

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")
}
4 changes: 3 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,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, errors.Trace(err)
}
Expand Down

0 comments on commit 325bc16

Please sign in to comment.