CREATEORREPLACETABLE t (pk INT, a INT, b int, KEY(a), PRIMARYKEY(pk DESC)) ENGINE=InnoDB;
INSERTINTO t VALUES (1,4,5),(2,9,6),(3,NULL,7),(4,NULL,8);
ANALYZE TABLE t PERSISTENT FORALL; # Optional, fails either way
SELECT * FROM t WHERE pk > 10 OR a > 0;
# Cleanup
DROPTABLE t;
The query returns an empty result set (the expected result is 2 rows):
preview-10.8-MDEV-13756-desc-indexes 49b38c82
SELECT * FROM t WHERE pk > 10 OR a > 0;
pk a b
Not reproducible with the same test case with ASC primary key.
Not reproducible with the same test case with MyISAM.
Not reproducible with index_merge=off.
EXPLAIN
EXPLAIN
{
"query_block": {
"select_id": 1,
"nested_loop": [
{
"table": {
"table_name": "t",
"access_type": "index_merge",
"possible_keys": ["PRIMARY", "a"],
"key_length": "5,4",
"index_merge": {
"sort_union": [
{
"range": {
"key": "a",
"used_key_parts": ["a"]
}
},
{
"range": {
"key": "PRIMARY",
"used_key_parts": []
}
}
]
},
"rows": 3,
"filtered": 100,
"attached_condition": "t.pk > 10 or t.a > 0"
}
}
]
}
}
Attachments
Issue Links
is caused by
MDEV-13756Implement descending index: KEY (a DESC, b ASC)
Notes: This quick select uses a special case variant of index_merge where one of the merged index scans is a scan on clustered PK.
In that case, the execution gets here:
(gdb) wher 10
#0 QUICK_RANGE_SELECT::cmp_next (this=0x7fff9809e690, range_arg=0x7fff98017ef8) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:13079
#1 0x0000555555d95cf4 in QUICK_RANGE_SELECT::row_in_ranges (this=0x7fff9809e690) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:12889
#2 0x0000555555d94252 in read_keys_and_merge_scans (thd=0x7fff98000d78, head=0x7fff9801fe78, quick_selects=..., pk_quick_select=0x7fff9809e690, read_record=0x7fff980235d0, intersection=false, filtered_scans=0x0, unique_ptr=0x7fff98023560) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:12289
#3 0x0000555555d9443f in QUICK_INDEX_MERGE_SELECT::read_keys_and_merge (this=0x7fff98023520) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:12323
#4 0x0000555555d7857b in QUICK_INDEX_SORT_SELECT::reset (this=0x7fff98023520) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:1400
and QUICK_RANGE_SELECT::cmp_next() apparently ignores the fact that some key parts are reverse-ordered.
Sergei Petrunia
added a comment - Notes: This quick select uses a special case variant of index_merge where one of the merged index scans is a scan on clustered PK.
In that case, the execution gets here:
(gdb) wher 10
#0 QUICK_RANGE_SELECT::cmp_next (this=0x7fff9809e690, range_arg=0x7fff98017ef8) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:13079
#1 0x0000555555d95cf4 in QUICK_RANGE_SELECT::row_in_ranges (this=0x7fff9809e690) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:12889
#2 0x0000555555d94252 in read_keys_and_merge_scans (thd=0x7fff98000d78, head=0x7fff9801fe78, quick_selects=..., pk_quick_select=0x7fff9809e690, read_record=0x7fff980235d0, intersection=false, filtered_scans=0x0, unique_ptr=0x7fff98023560) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:12289
#3 0x0000555555d9443f in QUICK_INDEX_MERGE_SELECT::read_keys_and_merge (this=0x7fff98023520) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:12323
#4 0x0000555555d7857b in QUICK_INDEX_SORT_SELECT::reset (this=0x7fff98023520) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:1400
and QUICK_RANGE_SELECT::cmp_next() apparently ignores the fact that some key parts are reverse-ordered.
People
Sergei Petrunia
Elena Stepanova
Votes:
0Vote for this issue
Watchers:
3Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1262.7999999523163,"ttfb":365,"pageVisibility":"visible","entityId":106405,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"d5afb25b-035f-4b77-8081-0ccd58a365b0","navigationType":0,"readyForUser":1417.7999999523163,"redirectCount":0,"resourceLoadedEnd":953,"resourceLoadedStart":376.2000000476837,"resourceTiming":[{"duration":90.20000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":376.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":376.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":466.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":90.20000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":376.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":376.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":466.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":368.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":376.60000014305115,"connectEnd":376.60000014305115,"connectStart":376.60000014305115,"domainLookupEnd":376.60000014305115,"domainLookupStart":376.60000014305115,"fetchStart":376.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":473.2000000476837,"responseEnd":744.7999999523163,"responseStart":499.7999999523163,"secureConnectionStart":376.60000014305115},{"duration":576.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":376.90000009536743,"connectEnd":376.90000009536743,"connectStart":376.90000009536743,"domainLookupEnd":376.90000009536743,"domainLookupStart":376.90000009536743,"fetchStart":376.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":473.5,"responseEnd":953,"responseStart":500.40000009536743,"secureConnectionStart":376.90000009536743},{"duration":147.70000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":377,"connectEnd":377,"connectStart":377,"domainLookupEnd":377,"domainLookupStart":377,"fetchStart":377,"redirectEnd":0,"redirectStart":0,"requestStart":473.90000009536743,"responseEnd":524.7000000476837,"responseStart":519.4000000953674,"secureConnectionStart":377},{"duration":147.70000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":377.2000000476837,"connectEnd":377.2000000476837,"connectStart":377.2000000476837,"domainLookupEnd":377.2000000476837,"domainLookupStart":377.2000000476837,"fetchStart":377.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":474.7000000476837,"responseEnd":524.9000000953674,"responseStart":520.1000001430511,"secureConnectionStart":377.2000000476837},{"duration":148.10000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":377.2999999523163,"connectEnd":377.2999999523163,"connectStart":377.2999999523163,"domainLookupEnd":377.2999999523163,"domainLookupStart":377.2999999523163,"fetchStart":377.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":475.2000000476837,"responseEnd":525.4000000953674,"responseStart":521.1000001430511,"secureConnectionStart":377.2999999523163},{"duration":96.20000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":377.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":377.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":473.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":148,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":377.7999999523163,"connectEnd":377.7999999523163,"connectStart":377.7999999523163,"domainLookupEnd":377.7999999523163,"domainLookupStart":377.7999999523163,"fetchStart":377.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":477.2000000476837,"responseEnd":525.7999999523163,"responseStart":521.6000001430511,"secureConnectionStart":377.7999999523163},{"duration":99,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":377.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":377.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":476.90000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":150.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":378.10000014305115,"connectEnd":378.10000014305115,"connectStart":378.10000014305115,"domainLookupEnd":378.10000014305115,"domainLookupStart":378.10000014305115,"fetchStart":378.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":495.7000000476837,"responseEnd":528.4000000953674,"responseStart":527.2000000476837,"secureConnectionStart":378.10000014305115},{"duration":566,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":381.40000009536743,"connectEnd":381.40000009536743,"connectStart":381.40000009536743,"domainLookupEnd":381.40000009536743,"domainLookupStart":381.40000009536743,"fetchStart":381.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":561.2999999523163,"responseEnd":947.4000000953674,"responseStart":938.2000000476837,"secureConnectionStart":381.40000009536743},{"duration":566.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":381.90000009536743,"connectEnd":381.90000009536743,"connectStart":381.90000009536743,"domainLookupEnd":381.90000009536743,"domainLookupStart":381.90000009536743,"fetchStart":381.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":574.7999999523163,"responseEnd":948.7000000476837,"responseStart":942.6000001430511,"secureConnectionStart":381.90000009536743},{"duration":98.80000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":922.2999999523163,"connectEnd":922.2999999523163,"connectStart":922.2999999523163,"domainLookupEnd":922.2999999523163,"domainLookupStart":922.2999999523163,"fetchStart":922.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":984.7999999523163,"responseEnd":1021.1000001430511,"responseStart":1020.2000000476837,"secureConnectionStart":922.2999999523163},{"duration":350.30000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1218.2999999523163,"connectEnd":1218.2999999523163,"connectStart":1218.2999999523163,"domainLookupEnd":1218.2999999523163,"domainLookupStart":1218.2999999523163,"fetchStart":1218.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":1535.2000000476837,"responseEnd":1568.6000001430511,"responseStart":1567.7999999523163,"secureConnectionStart":1218.2999999523163},{"duration":290.40000009536743,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1302.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1302.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1592.9000000953674,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":128,"domainLookupEnd":143,"connectStart":143,"connectEnd":173,"secureConnectionStart":162,"requestStart":174,"responseStart":365,"responseEnd":380,"domLoading":369,"domInteractive":1612,"domContentLoadedEventStart":1612,"domContentLoadedEventEnd":1669,"domComplete":1885,"loadEventStart":1885,"loadEventEnd":1886,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1483},{"name":"bigPipe.sidebar-id.end","time":1483.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":1484},{"name":"bigPipe.activity-panel-pipe-id.end","time":1485},{"name":"activityTabFullyLoaded","time":1686.6000001430511}],"measures":[],"correlationId":"77ac50967b1103","effectiveType":"4g","downlink":9.2,"rtt":0,"serverDuration":101,"dbReadsTimeInMs":11,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Notes: This quick select uses a special case variant of index_merge where one of the merged index scans is a scan on clustered PK.
In that case, the execution gets here:
(gdb) wher 10
#0 QUICK_RANGE_SELECT::cmp_next (this=0x7fff9809e690, range_arg=0x7fff98017ef8) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:13079
#1 0x0000555555d95cf4 in QUICK_RANGE_SELECT::row_in_ranges (this=0x7fff9809e690) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:12889
#2 0x0000555555d94252 in read_keys_and_merge_scans (thd=0x7fff98000d78, head=0x7fff9801fe78, quick_selects=..., pk_quick_select=0x7fff9809e690, read_record=0x7fff980235d0, intersection=false, filtered_scans=0x0, unique_ptr=0x7fff98023560) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:12289
#3 0x0000555555d9443f in QUICK_INDEX_MERGE_SELECT::read_keys_and_merge (this=0x7fff98023520) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:12323
#4 0x0000555555d7857b in QUICK_INDEX_SORT_SELECT::reset (this=0x7fff98023520) at /home/psergey/dev-git2/10.8-rev-index/sql/opt_range.cc:1400
and QUICK_RANGE_SELECT::cmp_next() apparently ignores the fact that some key parts are reverse-ordered.