Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: disable projection elimination for select plan of update #10962

Merged
merged 4 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions planner/core/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1090,3 +1090,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")
}
4 changes: 3 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether there will be some bugs if we disable the projection elimination rule. As you mentioned in the PR description that "The root cause of the error is that during projection elimination, we do not resolve columns in OrderedList field of Update", can we fix this issue in the projection elimination rule for the Update operator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we need to pass an additional parameter of type Assignment to DoOptimize, it is pretty ugly and ad-hoc IMHO.

if err != nil {
return nil, err
}
Expand Down