-
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
plan, expression: support is null
in hash partition pruning
#17281
Conversation
Codecov Report
@@ Coverage Diff @@
## master #17281 +/- ##
================================================
- Coverage 79.7957% 79.7956% -0.0002%
================================================
Files 520 517 -3
Lines 139624 139534 -90
================================================
- Hits 111414 111342 -72
+ Misses 19238 19230 -8
+ Partials 8972 8962 -10 |
expression/partition_pruner.go
Outdated
switch pi := piExpr.(type) { | ||
case *ScalarFunction: | ||
if pi.FuncName.L == ast.Plus || pi.FuncName.L == ast.Minus || pi.FuncName.L == ast.Mul || pi.FuncName.L == ast.Div { | ||
left, right := pi.GetArgs()[0], pi.GetArgs()[1] | ||
leftVal, ok, isNil := p.tryEvalPartitionExpr(left) | ||
leftVal, ok, isNull := p.tryEvalPartitionExpr(left) | ||
if !ok { |
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.
if !ok || isNull ?
LGTM |
@tiancaiamao @XuHuaiyu PTAL |
expression/partition_pruner.go
Outdated
if err != nil { | ||
return 0, false, false | ||
} else if isNull { | ||
return 0, true, true | ||
} | ||
return ret, true, false |
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.
return ret, true, isNull
is enough?
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.
yes, for expression like (year(null) + 2)
or year(null)
, MySQL and TiDB both produce NULL
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 I mean is that:
we can remove line 140~141, and change line 143 to return ret, true, isNull
"explain select * from t4 where d = '2019-10-07 10:40:00' and a = 1", | ||
"explain select * from t5 where d = '2019-10-07'" | ||
"explain select * from t5 where d = '2019-10-07'", | ||
"explain select * from t6 where a is null", |
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.
add a case for explain select * from t6 where b is null
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.
done, PTAL
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.
LGTM
/merge |
/run-all-tests |
@imtbkcat merge failed. |
/merge |
/run-all-tests |
/merge |
Your auto merge job has been accepted, waiting for:
|
/run-all-tests |
Signed-off-by: sre-bot <sre-bot@pingcap.com>
cherry pick to release-3.0 in PR #17308 |
Signed-off-by: sre-bot <sre-bot@pingcap.com>
cherry pick to release-3.1 in PR #17309 |
cherry pick to release-4.0 in PR #17310 |
What problem does this PR solve?
Problem Summary:
SQL like
select * from t where a is null
will produce a full table scan plan in hash partition. For example:This SQL will produce following result:
What is changed and how it works?
Proposal: xxx
What's Changed:
During partition pruning, if a column is equal to
NULL
, all calculation relating to it will produce null result and set aNULL
flag.How it Works:
If pruning result with a
NULL
flag, it will be point top0
.Related changes
Check List
Tests
Side effects
Release note
is null
filter condition in hash partition pruning