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

Conversation

eurekaka
Copy link
Contributor

What problem does this PR solve?

Before this PR:

mysql> create table t(a int, b int);
Query OK, 0 rows affected (0.01 sec)

mysql> explain update t t1, (select distinct b from t) t2 set t1.b = t2.b;
ERROR 1105 (HY000): Can't find column test.t2.b in schema Column: [test.t1.a,test.t1.b,test.t1._tidb_rowid,test.t.b] Unique key: []

What is changed and how it works?

The root cause of the error is that during projection elimination, we do not resolve columns in OrderedList field of Update, so this PR avoid this by reset the flagProjectionElimination when building select plan for update.

Check List

Tests

  • Unit test

Code changes

N/A

Side effects

N/A

Related changes

  • Need to cherry-pick to the release branch

@eurekaka eurekaka added type/bugfix This PR fixes a bug. sig/planner SIG: Planner labels Jun 27, 2019
@codecov
Copy link

codecov bot commented Jun 27, 2019

Codecov Report

Merging #10962 into master will increase coverage by 0.2036%.
The diff coverage is n/a.

@@               Coverage Diff               @@
##            master     #10962        +/-   ##
===============================================
+ Coverage   81.274%   81.4776%   +0.2036%     
===============================================
  Files          423        423                
  Lines        90094      90793       +699     
===============================================
+ Hits         73223      73976       +753     
+ Misses       11575      11512        -63     
- Partials      5296       5305         +9

@eurekaka
Copy link
Contributor Author

/run-all-tests

@eurekaka eurekaka added the priority/P1 The issue has P1 priority. label Jun 27, 2019
Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

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

LGTM

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.

@XuHuaiyu XuHuaiyu added the priority/release-blocker This issue blocks a release. Please solve it ASAP. label Jul 9, 2019
@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Jul 9, 2019

Can we set Update.Schema to the SelectPlan.Schema after SelectPlan is optimized?

@eurekaka
Copy link
Contributor Author

@XuHuaiyu The error is raised because column in OrderedList of Update cannot find match in schema of SelectPlan, so I think setting schema of Update would not help.

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

lgtm

@eurekaka eurekaka added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 15, 2019
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@eurekaka eurekaka merged commit 3f1d234 into pingcap:master Jul 15, 2019
@eurekaka eurekaka deleted the proj_elim branch July 15, 2019 08:27
eurekaka added a commit to eurekaka/tidb that referenced this pull request Jul 15, 2019
…ngcap#10962)

Conflicts:
	planner/core/cbo_test.go
	planner/core/logical_plan_builder.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/P1 The issue has P1 priority. priority/release-blocker This issue blocks a release. Please solve it ASAP. sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants