-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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 name ambiguous check when building natural join without filter #36012
planner: fix name ambiguous check when building natural join without filter #36012
Conversation
[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/f6853c670b2190f4f99342629e9adb7db01056d4 |
planner/core/logical_plan_builder.go
Outdated
// t1 natural join (t3 cross join t4) | ||
// t3 and t4 may generate the same name column from cross join. | ||
// for every common column of natural join, the name from right or left should be exactly one. | ||
checkAmbiguous := func(lnames, rnames types.NameSlice) error { |
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.
I think we don't need to make it a separate function here because we don't reuse this logic.
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.
make sense
planner/core/logical_plan_builder.go
Outdated
// t3 and t4 may generate the same name column from cross join. | ||
// for every common column of natural join, the name from right or left should be exactly one. | ||
checkAmbiguous := func(lnames, rnames types.NameSlice) error { | ||
// step1: find the common names first |
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.
Where is "step2"? 🤣
planner/core/logical_plan_builder.go
Outdated
// record left map | ||
if cnt, ok := lNameMap[name.ColName.L]; ok { | ||
lNameMap[name.ColName.L] = cnt + 1 | ||
} else { | ||
lNameMap[name.ColName.L] = 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.
What about map["v"] = map["v"] + 1
? If it is not in the map, the default value of int
will be returned, i.e. 0.
Since int is not a pointer, I think there is no need to use v, ok := map...
and check ok
.
planner/core/logical_plan_builder.go
Outdated
if cnt > 1 { | ||
return ErrAmbiguous.GenWithStackByArgs(name.ColName.L, "from clause") | ||
} | ||
commonNames = append(commonNames, name.ColName.L) |
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.
Seems we can also check "the right map" here, and don't need to maintain the commonNames
.
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.
/retest
@AilinKid: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
ca37aca
to
56a6df7
Compare
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #36012 +/- ##
================================================
+ Coverage 70.4861% 72.6344% +2.1483%
================================================
Files 1463 1463
Lines 433217 433271 +54
================================================
+ Hits 305358 314704 +9346
+ Misses 108613 98699 -9914
- Partials 19246 19868 +622
Flags with carried forward coverage won't be shown. Click here to find out more.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hawkingrei, qw4990 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
@AilinKid: The following test 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. |
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.
/retest
@AilinKid: Cannot trigger testing until a trusted user reviews the PR and leaves an In response to this:
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. |
// check left map | ||
if cnt, ok := lNameMap[name.ColName.L]; ok { | ||
if cnt > 1 { | ||
return ErrAmbiguous.GenWithStackByArgs(name.ColName.L, "from clause") |
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.
ErrAmbiguous
shoud be plannererrors.ErrAmbiguous
. ErrAmbiguous
have been moved into pkg/util/dbterror/plannererrors
.
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.
make sense
Signed-off-by: AilinKid <314806019@qq.com>
Signed-off-by: AilinKid <314806019@qq.com>
Signed-off-by: AilinKid <314806019@qq.com>
d68fa5f
to
f2a6a04
Compare
/cherry-pick release-7.5 |
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot: new pull request could not be created: failed to create pull request against pingcap/tidb#release-7.5 from head ti-chi-bot:cherry-pick-36012-to-release-7.5: status code 422 not one of [201], body: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"A pull request already exists for ti-chi-bot:cherry-pick-36012-to-release-7.5."}],"documentation_url":"https://docs.github.com/rest/pulls/pulls#create-a-pull-request"} In response to this:
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 ti-community-infra/tichi repository. |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
Signed-off-by: AilinKid 314806019@qq.com
What problem does this PR solve?
Issue Number: close #32044
Problem Summary:
What is changed and how it works?
natural join without a filter may find their common columns from both sides first.
then, for every common column, we need to make sure that there is exactly one column matches the name for each side.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.