-
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
util: skip always false DNF #51901
util: skip always false DNF #51901
Conversation
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #51901 +/- ##
=================================================
- Coverage 70.7435% 55.2386% -15.5050%
=================================================
Files 1477 1592 +115
Lines 438550 616970 +178420
=================================================
+ Hits 310246 340806 +30560
- Misses 108884 252967 +144083
- Partials 19420 23197 +3777
Flags with carried forward coverage won't be shown. Click here to find out more.
|
This comment was marked as outdated.
This comment was marked as outdated.
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
7d997d1
to
e9ba0c1
Compare
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
c53ffc6
to
3f24681
Compare
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
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.
🔢 Self-check (PR reviewed by myself and ready for feedback.)
require.Regexp(t, ".*IndexFullScan.*", res.Rows()[2][0]) | ||
require.Len(t, res.Rows(), 2) | ||
require.Regexp(t, ".*IndexReader.*", res.Rows()[0][0]) | ||
require.Regexp(t, ".*IndexRangeScan.*", res.Rows()[1][0]) | ||
|
||
res = tk.MustQuery("explain format = 'brief' select col1 from UK_GCOL_VIRTUAL_18588 use index(UK_COL1) " + | ||
"where col1 between -1696020282760139948 and -2619168038882941276 or col1 < -4004648990067362699;") |
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.
-1696020282760139948 > -2619168038882941276. So this is an empty range.
INSERT INTO `t` VALUES (2065948,1999,_binary '8jxN','rf',-54,-5656,'1987-07-03',259254,'7me坨'),(-8248164,2024,_binary 'zA5A','s)DAkX3',-93,-12983,'2027-12-18',299573,'LUf咲'),(-6131509,2023,_binary 'xdex#Y2','1th%h',-51,19149,'2013-10-28',428279,'矷莒X'),(7545837,1998,_binary 'PCVO','&(lJw6',30,4093,'1987-07-03',736235,'腏@TOIJ'),(-7449472,2029,_binary 'B7&jrl','EjbFfX!',80,-7590,'2011-11-03',765580,'堮ZQF_'),(-7176200,1988,_binary 'tiPglv7mX_#','CnCtNb',-25,NULL,'1987-07-03',842956,'Gq羣嗳殓'),(-115168,2036,_binary 'BqmX$-4It','!8#dvH',82,18787,'1991-09-20',921706,'椉2庘v'),(6665100,1987,_binary '4IJgk0fr4','(D',-73,28628,'1987-07-03',1149668,'摔玝S渉'),(-4065661,2021,_binary '8G%','xDO39xw#',-107,17356,'1970-12-20',1316239,'+0c35掬-阗'),(7622462,1990,_binary '&o+)s)D0','kjoS9Dzld',84,688,'1987-07-03',1403663,'$H鍿_M~'),(5269354,2018,_binary 'wq9hC8','s8XPrN+',-2,-31272,'2008-05-26',1534517,'y椁n躁Q'),(2065948,1982,_binary '8jxNjbksV','g$+i4dg',11,19800,'1987-07-03',1591457,'z^+H~薼A'),(4076971,2024,_binary '&!RrsH','7Mpvk',-63,-632,'2032-10-28',1611011,'鬰+EXmx'),(3522062,1981,_binary ')nq#!UiHKk8','j~wFe77ai',50,6951,'1987-07-03',1716854,'J'),(7859777,2012,_binary 'PBA5xgJ&G&','UM7o!u',18,-5978,'1987-07-03',1967012,'e)浢L獹'),(2065948,2028,_binary '8jxNjbk','JmsEki9t4',51,12002,'2017-12-23',1981288,'mp氏襚'); | ||
explain format='brief' SELECT /*+ AGG_TO_COP() STREAM_AGG()*/ (NOT (`t`.`i`>=_UTF8MB4'j筧8') OR NOT (`t`.`i`=_UTF8MB4'暈lH忧ll6')) IS TRUE,MAX(`t`.`e`) AS `r0`,QUOTE(`t`.`i`) AS `r1` FROM `t` WHERE `t`.`h`>240817 OR `t`.`i` BETWEEN _UTF8MB4'WVz' AND _UTF8MB4'G#駧褉ZC領*lov' GROUP BY `t`.`i`; | ||
select count(*) from (SELECT /*+ AGG_TO_COP() STREAM_AGG()*/ (NOT (`t`.`i`>=_UTF8MB4'j筧8') OR NOT (`t`.`i`=_UTF8MB4'暈lH忧ll6')) IS TRUE,MAX(`t`.`e`) AS `r0`,QUOTE(`t`.`i`) AS `r1` FROM `t` WHERE `t`.`h`>240817 OR `t`.`i` BETWEEN _UTF8MB4'WVz' AND _UTF8MB4'G#駧褉ZC領*lov' GROUP BY `t`.`i`) derived; | ||
explain format='brief' SELECT /*+ AGG_TO_COP() */ (NOT (`t`.`i`>=_UTF8MB4'j筧8') OR NOT (`t`.`i`=_UTF8MB4'暈lH忧ll6')) IS TRUE,MAX(`t`.`e`) AS `r0`,QUOTE(`t`.`i`) AS `r1` FROM `t` WHERE `t`.`h`>240817 OR `t`.`i` BETWEEN _UTF8MB4'WVz' AND _UTF8MB4'G#駧褉ZC領*lov' GROUP BY `t`.`i`; |
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.
mysql> select 1 where _UTF8MB4'WVz' > _UTF8MB4'G#駧褉ZC領*lov';
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
mysql> select 1 where _UTF8MB4'WVz' < _UTF8MB4'G#駧褉ZC領*lov';
Empty set (0.00 sec)
/unhold |
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
@hawkingrei: Your lgtm message is repeated, so it is ignored. 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. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: AilinKid, hawkingrei 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:
|
In response to a cherrypick label: new pull request created to branch |
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>
What problem does this PR solve?
Issue Number: close #40997
Problem Summary:
For example:
In the where clause we have CNF contains some DNF and the last DNF is always false. But it will cause the optimizer to fall back to a full table scan.
The final plan looks like:
Actually, we can ignore this always false filter and do an index scan.
What changed and how does it work?
From the code details, we should ignore the empty range here:
tidb/pkg/util/ranger/detacher.go
Line 739 in 3f24681
In the
detachCNFCondAndBuildRangeForIndex
we will return directly from here if the range is empty:tidb/pkg/util/ranger/detacher.go
Line 315 in 3f24681
But we didn't consider it in the
detachDNFCondAndBuildRangeForIndex
.So I skip it here:
https://github.com/hi-rustin/tidb/blob/3f2468115cf4089d1bf47da3da4d06ca2dd31850/pkg/util/ranger/detacher.go#L740
I also updated the
TestIndexMergeIssue49605
test case. Because in this case we have an empty range:BETWEEN _UTF8MB4'WVz' AND _UTF8MB4'G#駧褉ZC領*lov'
. So that it doesn't use index merge anymore.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.