-
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
expression: Fixing Expression Rewrite Bug in Predicate Push Down for NULLIF with Type Mismatch #58588
base: master
Are you sure you want to change the base?
Conversation
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. |
[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. 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 |
ea1ab9d
to
76b60c8
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #58588 +/- ##
================================================
+ Coverage 73.1052% 73.5408% +0.4356%
================================================
Files 1676 1676
Lines 463369 463413 +44
================================================
+ Hits 338747 340798 +2051
+ Misses 103803 101772 -2031
- Partials 20819 20843 +24
Flags with carried forward coverage won't be shown. Click here to find out more.
|
What problem does this PR solve?
Issue Number: close #57647
Problem Summary:
What changed and how does it work?
The sql could be simplified as:
When rewriting the expression
nullif(3^1, case when (c0) then 91 end)
, it is transformed into:if(equals(3^1, case when (c0) then 91 end), null, 3^1)
.When building this function, the
RetType
ofnull
is inferred based on the type of3^1
, and a newRetType
is set.tidb/pkg/expression/builtin_control.go
Lines 713 to 720 in a82a3b4
Then, the SQL:
where (nullif(3^1, case when (c0) then 91 end)) in (select 1 from t0);
is rewritten to an inner join with otherConditions as:
nullif(3^1, case when (c0) then 91 end) = 1.
During
predicate push down
, it will try movingotherConditions
intoequal conditions
:tidb/pkg/planner/core/operator/logicalop/logical_join.go
Lines 1564 to 1572 in b11cce7
But when rewriting the
equal condition
, theRetType of null
has already been reset based on the earlier inference. Sore-inferring
of theRetType
of null and 3^1 will not match previous result, and the type finally becomesdecimal
.tidb/pkg/expression/builtin_control.go
Lines 279 to 289 in a82a3b4
The constant 1 will be wrapped with a
(cast as decimal)
, making it no longer a column, which ultimately leads to the error.I modified the
ifInferType4ControlFuncs()
method to determine whether a value is null. If a constant'svalue.
k is null, it will also be treated as null.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.