Type:
New Feature
Priority:
Major
Resolution:
Fixed
Currently, Index Condition Pushdown (and Rowid Filtering) cannot be used with reverse-ordered index scans.
Search for IndexConditionPushdownAndReverseScans, RowidFilteringAndReverseScans in sql/sql_select.cc for detailed explanation why.
See prepare_for_reverse_ordered_access() where we disable these features when switching to reverse scans.
This task is about enabling ICP (and maybe Rowid Filtering) to work with reverse-ordered scans.
re MySQL 8
MySQL 8 actually supports ICP + Reverse scans, see handler::set_end_range call. Maybe we should adopt this, or maybe something something similar.
Some more details about how they support it: Support added by this patch:
https://github.com/mysql/mysql-server/commit/da1d92fd46071cd86de61058b6ea39fd9affcd87
create table ten(a int );
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table one_k(a int );
insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C;
create table t10 (a int , b int , c int , key (a,b));
insert into t10 select a,a,a from one_k;
explain select * from t10 force index (a) where a between 10 and 20 and b+1 <3333 order by a desc , b desc ;
+----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+--------------------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+--------------------------------------------+
| 1 | SIMPLE | t10 | NULL | range | a | a | 5 | NULL | 1 | 100.00 | Using index condition; Backward index scan |
+----+-------------+-------+------------+-------+---------------+------+---------+------+------+----------+--------------------------------------------+
As pointed out by igor , there is some interesting limitation: reverse index scan+ICP doesn't work with ref access:
mysql> explain select * from t10 force index(a) where a=10 and b+1 <3333 order by a desc, b desc;
+----+-------------+-------+------------+------+---------------+------+---------+-------+------+----------+----------------------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+-------+------+----------+----------------------------------+
| 1 | SIMPLE | t10 | NULL | ref | a | a | 5 | const | 1 | 100.00 | Using where; Backward index scan |
+----+-------------+-------+------------+------+---------------+------+---------+-------+------+----------+----------------------------------+
mysql> explain select * from t10 force index(a) where a=10 and b+1 <3333 order by a asc, b asc;
+----+-------------+-------+------------+------+---------------+------+---------+-------+------+----------+-----------------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+-------+------+----------+-----------------------+
| 1 | SIMPLE | t10 | NULL | ref | a | a | 5 | const | 1 | 100.00 | Using index condition |
+----+-------------+-------+------------+------+---------------+------+---------+-------+------+----------+-----------------------+
1 row in set, 1 warning (0.01 sec)
code-wise, it is here:
void QEP_TAB::push_index_cond( const JOIN_TAB *join_tab, uint keyno,
Opt_trace_object *trace_obj) {
JOIN * const join_ = join();
DBUG_TRACE;
ASSERT_BEST_REF_IN_JOIN_ORDER(join_);
assert (join_tab == join_->best_ref[idx()]);
if (join_tab->reversed_access) // @todo: historical limitation, lift it!
return ;
{"report":{"fcp":1364,"ttfb":443.5,"pageVisibility":"visible","entityId":129623,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"8e408754-4357-4847-ad2d-0f7e87c72d60","navigationType":0,"readyForUser":1449.3999996185303,"redirectCount":0,"resourceLoadedEnd":1070.1999998092651,"resourceLoadedStart":453.69999980926514,"resourceTiming":[{"duration":139.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":453.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":453.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":593,"responseStart":0,"secureConnectionStart":0},{"duration":139.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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","startTime":454,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":454,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":593.5,"responseStart":0,"secureConnectionStart":0},{"duration":484.9000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":454.0999994277954,"connectEnd":454.0999994277954,"connectStart":454.0999994277954,"domainLookupEnd":454.0999994277954,"domainLookupStart":454.0999994277954,"fetchStart":454.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":598.8999996185303,"responseEnd":939,"responseStart":656.0999994277954,"secureConnectionStart":454.0999994277954},{"duration":615.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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","startTime":454.3999996185303,"connectEnd":454.3999996185303,"connectStart":454.3999996185303,"domainLookupEnd":454.3999996185303,"domainLookupStart":454.3999996185303,"fetchStart":454.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":599.8000001907349,"responseEnd":1070.1999998092651,"responseStart":689.0999994277954,"secureConnectionStart":454.3999996185303},{"duration":206.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":454.5,"connectEnd":454.5,"connectStart":454.5,"domainLookupEnd":454.5,"domainLookupStart":454.5,"fetchStart":454.5,"redirectEnd":0,"redirectStart":0,"requestStart":600.1999998092651,"responseEnd":661.0999994277954,"responseStart":657.8000001907349,"secureConnectionStart":454.5},{"duration":206.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":454.69999980926514,"connectEnd":454.69999980926514,"connectStart":454.69999980926514,"domainLookupEnd":454.69999980926514,"domainLookupStart":454.69999980926514,"fetchStart":454.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":601.5,"responseEnd":661.3999996185303,"responseStart":658.3999996185303,"secureConnectionStart":454.69999980926514},{"duration":206.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":454.8999996185303,"connectEnd":454.8999996185303,"connectStart":454.8999996185303,"domainLookupEnd":454.8999996185303,"domainLookupStart":454.8999996185303,"fetchStart":454.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":602.8000001907349,"responseEnd":661.6999998092651,"responseStart":659,"secureConnectionStart":454.8999996185303},{"duration":146.89999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":455.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":455.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":602.0999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":206.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":455.3999996185303,"connectEnd":455.3999996185303,"connectStart":455.3999996185303,"domainLookupEnd":455.3999996185303,"domainLookupStart":455.3999996185303,"fetchStart":455.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":604.5999994277954,"responseEnd":662,"responseStart":659.5,"secureConnectionStart":455.3999996185303},{"duration":147.89999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/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":455.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":455.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":603.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":206.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/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":455.5999994277954,"connectEnd":455.5999994277954,"connectStart":455.5999994277954,"domainLookupEnd":455.5999994277954,"domainLookupStart":455.5999994277954,"fetchStart":455.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":605.8999996185303,"responseEnd":662.1999998092651,"responseStart":660.0999994277954,"secureConnectionStart":455.5999994277954},{"duration":585.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":456.5999994277954,"connectEnd":456.5999994277954,"connectStart":456.5999994277954,"domainLookupEnd":456.5999994277954,"domainLookupStart":456.5999994277954,"fetchStart":456.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":729.1999998092651,"responseEnd":1042,"responseStart":1034.0999994277954,"secureConnectionStart":456.5999994277954},{"duration":587.1000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":456.69999980926514,"connectEnd":456.69999980926514,"connectStart":456.69999980926514,"domainLookupEnd":456.69999980926514,"domainLookupStart":456.69999980926514,"fetchStart":456.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":802.8000001907349,"responseEnd":1043.8000001907349,"responseStart":1039,"secureConnectionStart":456.69999980926514},{"duration":170.9000005722046,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1067.5999994277954,"connectEnd":1067.5999994277954,"connectStart":1067.5999994277954,"domainLookupEnd":1067.5999994277954,"domainLookupStart":1067.5999994277954,"fetchStart":1067.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":1201.5999994277954,"responseEnd":1238.5,"responseStart":1238,"secureConnectionStart":1067.5999994277954}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":249,"responseStart":444,"responseEnd":449,"domLoading":451,"domInteractive":1519,"domContentLoadedEventStart":1521,"domContentLoadedEventEnd":1577,"domComplete":2518,"loadEventStart":2518,"loadEventEnd":2519,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1495},{"name":"bigPipe.sidebar-id.end","time":1495.8999996185303},{"name":"bigPipe.activity-panel-pipe-id.start","time":1496},{"name":"bigPipe.activity-panel-pipe-id.end","time":1497.5},{"name":"activityTabFullyLoaded","time":1594}],"measures":[],"correlationId":"dbbf5f7296f6dc","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":103,"dbReadsTimeInMs":12,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I have removed the fixVersion from this ticket as it is unlikely to be in 11.7 with status open, priority major and unassigned
serg, FYI