-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
preprocessor: fix the non-unique table error when do name resolution across database #34887
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: AilinKid <314806019@qq.com>
[REVIEW NOTIFICATION] This pull request has not been approved. To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/25e2984385f950960b33507ea1d28d93f55cf24a |
Signed-off-by: AilinKid <314806019@qq.com>
Signed-off-by: AilinKid <314806019@qq.com>
var dbName4DerivedTable model.CIStr | ||
if isSubQuery { | ||
// change the derived table's database name. | ||
asName := x.AsName | ||
x.AsName = model.NewCIStr("") | ||
var sb strings.Builder | ||
// (select * from t) as t1 => db name as (select * from t) | ||
err = x.Restore(format.NewRestoreCtx(0, &sb)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
dbName4DerivedTable = model.NewCIStr(sb.String()) | ||
x.AsName = asName | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this code block? If strange that we add such a database name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mainly target at this cast:select * from db1.t as t1, (select * from t) as t1;
the first half‘s schema is db1.t1.a
the second half's schema is currentDB(db1).t1.a
so this two will lead to ambiguous problems. (MySQL won't)
select * from db1.t as t1, db2.t as t1;
while this case can succeed, because
the first half‘s schema is db1.t1.a
the second half's schema is db2.t1.a
So according to the above, I think MySQL does distinguish the derived table's DB-name
Signed-off-by: AilinKid <314806019@qq.com>
@@ -3820,6 +3844,10 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L | |||
} | |||
} | |||
|
|||
if strings.HasPrefix(b.ctx.GetSessionVars().StmtCtx.OriginalSQL, "SELECT LAST_VALUE((SELECT upper.j FROM t LIMIT 1)) OVER (PARTITION BY i) FROM t AS upper") { | |||
fmt.Println(1) | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional? Looks like for debug usage?
@AilinKid: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
Signed-off-by: AilinKid 314806019@qq.com
What problem does this PR solve?
Issue Number: close #24563, close #24550
Problem Summary:
What is changed and how it works?
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.