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":670.7999999523163,"ttfb":158.40000009536743,"pageVisibility":"visible","entityId":129623,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"2480ae47-d094-4466-9700-4ed96718a6e6","navigationType":0,"readyForUser":741,"redirectCount":0,"resourceLoadedEnd":721.4000000953674,"resourceLoadedStart":164.5,"resourceTiming":[{"duration":6.599999904632568,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":164.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":164.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":171.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":6.700000047683716,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":164.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":164.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":171.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":68.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":164.90000009536743,"connectEnd":164.90000009536743,"connectStart":164.90000009536743,"domainLookupEnd":164.90000009536743,"domainLookupStart":164.90000009536743,"fetchStart":164.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":164.90000009536743,"responseEnd":233.70000004768372,"responseStart":233.70000004768372,"secureConnectionStart":164.90000009536743},{"duration":102.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":164.90000009536743,"connectEnd":164.90000009536743,"connectStart":164.90000009536743,"domainLookupEnd":164.90000009536743,"domainLookupStart":164.90000009536743,"fetchStart":164.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":164.90000009536743,"responseEnd":267.5,"responseStart":267.5,"secureConnectionStart":164.90000009536743},{"duration":105.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":165.09999990463257,"connectEnd":165.09999990463257,"connectStart":165.09999990463257,"domainLookupEnd":165.09999990463257,"domainLookupStart":165.09999990463257,"fetchStart":165.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":165.09999990463257,"responseEnd":270.90000009536743,"responseStart":270.90000009536743,"secureConnectionStart":165.09999990463257},{"duration":106.70000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":165.09999990463257,"connectEnd":165.09999990463257,"connectStart":165.09999990463257,"domainLookupEnd":165.09999990463257,"domainLookupStart":165.09999990463257,"fetchStart":165.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":165.09999990463257,"responseEnd":271.7999999523163,"responseStart":271.7999999523163,"secureConnectionStart":165.09999990463257},{"duration":108.20000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":165.29999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":165.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":273.5,"responseStart":0,"secureConnectionStart":0},{"duration":106.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":165.29999995231628,"connectEnd":165.29999995231628,"connectStart":165.29999995231628,"domainLookupEnd":165.29999995231628,"domainLookupStart":165.29999995231628,"fetchStart":165.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":165.29999995231628,"responseEnd":272.2000000476837,"responseStart":272.2000000476837,"secureConnectionStart":165.29999995231628},{"duration":107.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":165.40000009536743,"connectEnd":165.40000009536743,"connectStart":165.40000009536743,"domainLookupEnd":165.40000009536743,"domainLookupStart":165.40000009536743,"fetchStart":165.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":165.40000009536743,"responseEnd":272.7000000476837,"responseStart":272.7000000476837,"secureConnectionStart":165.40000009536743},{"duration":108,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":165.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":165.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":273.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":107.70000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":165.70000004768372,"connectEnd":165.70000004768372,"connectStart":165.70000004768372,"domainLookupEnd":165.70000004768372,"domainLookupStart":165.70000004768372,"fetchStart":165.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":165.70000004768372,"responseEnd":273.40000009536743,"responseStart":273.40000009536743,"secureConnectionStart":165.70000004768372},{"duration":544.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":171.40000009536743,"connectEnd":171.40000009536743,"connectStart":171.40000009536743,"domainLookupEnd":171.40000009536743,"domainLookupStart":171.40000009536743,"fetchStart":171.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":171.40000009536743,"responseEnd":715.7000000476837,"responseStart":715.7000000476837,"secureConnectionStart":171.40000009536743},{"duration":550,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":171.40000009536743,"connectEnd":171.40000009536743,"connectStart":171.40000009536743,"domainLookupEnd":171.40000009536743,"domainLookupStart":171.40000009536743,"fetchStart":171.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":171.40000009536743,"responseEnd":721.4000000953674,"responseStart":721.4000000953674,"secureConnectionStart":171.40000009536743},{"duration":250.59999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":469,"connectEnd":469,"connectStart":469,"domainLookupEnd":469,"domainLookupStart":469,"fetchStart":469,"redirectEnd":0,"redirectStart":0,"requestStart":469,"responseEnd":719.5999999046326,"responseStart":719.5999999046326,"secureConnectionStart":469},{"duration":79.10000014305115,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":649.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":649.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":728.2000000476837,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":14,"responseStart":158,"responseEnd":164,"domLoading":161,"domInteractive":842,"domContentLoadedEventStart":842,"domContentLoadedEventEnd":887,"domComplete":1687,"loadEventStart":1688,"loadEventEnd":1689,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":823.0999999046326},{"name":"bigPipe.sidebar-id.end","time":823.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":824},{"name":"bigPipe.activity-panel-pipe-id.end","time":826.5},{"name":"activityTabFullyLoaded","time":899.7999999523163}],"measures":[],"correlationId":"adae76b30e4c85","effectiveType":"4g","downlink":9.2,"rtt":0,"serverDuration":86,"dbReadsTimeInMs":11,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}