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: fix error when select view_name.col_name from view_name #14314

Merged
merged 6 commits into from
Jan 3, 2020

Conversation

XuHuaiyu
Copy link
Contributor

@XuHuaiyu XuHuaiyu commented Jan 2, 2020

What problem does this PR solve?

Before this commit:

tidb> create table t(a int);
Query OK, 0 rows affected (0.01 sec)
tidb> create view v as select * from t;
Query OK, 0 rows affected (0.01 sec)
tidb> desc select v.a from v;
ERROR 1054 (42S22): Unknown column 'v.a' in 'field list'

What is changed and how it works?

We build a projection upon the underlying select when execute select from a view.
The output name of the built projection should be view_name.col_name instead of underlying_table_name.col_name.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

N/A

Related changes

  • Need to cherry-pick to the release branch
    release-3.0, release-3.1

Release note

Fix an error when executing SQL like select view_name.col_name from view_name.

@XuHuaiyu XuHuaiyu added type/bugfix This PR fixes a bug. sig/planner SIG: Planner needs-cherry-pick-3.0 labels Jan 2, 2020
@XuHuaiyu XuHuaiyu requested a review from a team as a code owner January 2, 2020 06:38
@ghost ghost removed their request for review January 2, 2020 06:38
@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Jan 2, 2020

/run-all-tests

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Jan 2, 2020

/run-all-tests

@glorv
Copy link
Contributor

glorv commented Jan 2, 2020

/run-unit-test

Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

origColName := name.ColName
if tableInfo.View.Cols != nil {
origColName = tableInfo.View.Cols[i]
}
projNames = append(projNames, &types.FieldName{
TblName: name.TblName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment here for explanation?

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

@XuHuaiyu XuHuaiyu added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. labels Jan 3, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Jan 3, 2020

/run-all-tests

@XuHuaiyu
Copy link
Contributor Author

XuHuaiyu commented Jan 3, 2020

/merge

@sre-bot
Copy link
Contributor

sre-bot commented Jan 3, 2020

/run-all-tests

@sre-bot sre-bot merged commit d077284 into pingcap:master Jan 3, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Jan 3, 2020

cherry pick to release-3.0 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/can-merge Indicates a PR has been approved by a committer. 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