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

preprocessor: fix the non-unique table error when do name resolution across database #34887

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

AilinKid
Copy link
Contributor

@AilinKid AilinKid commented May 23, 2022

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

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

preprocessor: fix the non-unique table error when do name resolution across database

Signed-off-by: AilinKid <314806019@qq.com>
@AilinKid AilinKid requested a review from a team as a code owner May 23, 2022 08:28
@ti-chi-bot
Copy link
Member

[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 /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 23, 2022
@sre-bot
Copy link
Contributor

sre-bot commented May 23, 2022

Signed-off-by: AilinKid <314806019@qq.com>
Signed-off-by: AilinKid <314806019@qq.com>
@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 23, 2022
planner/core/preprocess.go Outdated Show resolved Hide resolved
Comment on lines +370 to +383
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
}
Copy link
Member

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.

Copy link
Contributor Author

@AilinKid AilinKid May 25, 2022

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>
@winoros
Copy link
Member

winoros commented May 26, 2022

MSViSjFFGE
MySQL is really strange. I think we just throw error in both situation

@@ -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)
}
Copy link
Contributor

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?

Copy link

ti-chi-bot bot commented Apr 10, 2024

@AilinKid: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/build 52ef358 link true /test build
idc-jenkins-ci-tidb/check_dev 52ef358 link true /test check-dev
idc-jenkins-ci-tidb/check_dev_2 52ef358 link true /test check-dev2
idc-jenkins-ci-tidb/mysql-test 52ef358 link true /test mysql-test
idc-jenkins-ci-tidb/unit-test 52ef358 link true /test unit-test
pull-integration-ddl-test 52ef358 link true /test pull-integration-ddl-test
pull-mysql-client-test 52ef358 link true /test pull-mysql-client-test
pull-br-integration-test 52ef358 link true /test pull-br-integration-test
pull-lightning-integration-test 52ef358 link true /test pull-lightning-integration-test

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wrong Not unique table/alias error report Not unique table/alias runs normally
5 participants