-
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
planner: Prevent OR Expressions in IN Subquery Conversion to INNER JOIN to Avoid Data Duplication #57584
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Hi @dash12653. Thanks for your PR. I'm waiting for a pingcap member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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-sigs/prow repository. |
Hi @dash12653. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. 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-sigs/prow repository. |
/ok-to-test |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #57584 +/- ##
================================================
+ Coverage 72.8590% 73.3545% +0.4955%
================================================
Files 1676 1676
Lines 463653 463865 +212
================================================
+ Hits 337813 340266 +2453
+ Misses 104979 102861 -2118
+ Partials 20861 20738 -123
Flags with carried forward coverage won't be shown. Click here to find out more.
|
What problem does this PR solve?
Issue Number: close #57390
Problem Summary:
What changed and how does it work?
This is the plan:
When tidb encounters an
IN subquery
, it tries to rewrite the outer table and subquery asINNER JOIN
.tidb/pkg/planner/core/expression_rewriter.go
Lines 1226 to 1242 in c091dba
When rewriting
OR expressions
(e.g., (c1 OR c1)), the kernel will convert the type of c1 toDOUBLE
.tidb/pkg/expression/builtin_cast.go
Lines 2556 to 2568 in c091dba
The join's condition is
(c1 OR c1) = c1
.We can check the output of the join condition for the left and right tables after converting INNER JOIN.
left output:
right output:
After the
DISTINCT
operation,CAST(c1 AS DOUBLE)
actually causes data duplication, which will lead to unexpected results forin operation
.To address this, I add a restriction who will check if the left expression is or function in the conditions for converting to an INNER JOIN.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.