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) #15572

Merged
merged 2 commits into from
Mar 24, 2020

Conversation

XuHuaiyu
Copy link
Contributor

cherry-pick #14314

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.

Copy link
Member

@francis0407 francis0407 left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -2426,7 +2426,7 @@ func (b *PlanBuilder) buildProjUponView(ctx context.Context, dbName model.CIStr,
}
projSchema.Append(&expression.Column{
UniqueID: b.ctx.GetSessionVars().AllocPlanColumnID(),
TblName: col.TblName,
TblName: tableInfo.Name,
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to change DBName?

Copy link
Member

Choose a reason for hiding this comment

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

@XuHuaiyu PTAL. BTW, we can merge this PR firstly. Changing the DBName in another PR if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch.
#15611

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

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

sre-bot commented Mar 24, 2020

Your auto merge job has been accepted, waiting for 15573

@sre-bot
Copy link
Contributor

sre-bot commented Mar 24, 2020

/run-all-tests

@sre-bot sre-bot merged commit 133bc93 into pingcap:release-3.0 Mar 24, 2020
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. type/3.0-cherry-pick
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants