Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
None
The following simple test case can demonstrate the problem:
set optimizer_switch= 'rowid_filter=off' ;
create table t1 (a int , b int , key (b), key (a)) engine=innodb;
insert into t1
select (rand(1)*1000)/10, (rand(1001)*1000)/50 from seq_1_to_1000;
analyze table t1 ;
explain extended select * from t1 where a in (17,51,5) and b=2;
MariaDB [test]> explain extended select * from t1 where a in (17,51,5) and b=2;
+------+-------------+-------+------+---------------+------+---------+-------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+-------+------+---------------+------+---------+-------+------+----------+-------------+
| 1 | SIMPLE | t1 | ref | b,a | b | 5 | const | 59 | 49.15 | Using where |
+------+-------------+-------+------+---------------+------+---------+-------+------+----------+-------------+
It can be seen from the output of the last command that the selectivity of the condition is shown as absurdly low (49.15%). In fact it is pretty high:
MariaDB [test]> explain extended select * from t1 where a in (17,51,5);
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+-----------------------+
| 1 | SIMPLE | t1 | range | a | a | 5 | NULL | 30 | 100.00 | Using index condition |
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+-----------------------+
It happens because after the commit 2acd81af73ac337658eb646ba2434f46a6dc8dc5 for MDEV-6003 : "EITS: ref access, keypart2=const vs keypart2=expr - inconsistent filtered% value" the function table_cond_selectivity() started discounting the selectivity of the condition b=2 twice:
the first time as a range condition:
sel /= (double)table->quick_rows[key] / (double) table->stat_records();
the second time as the ref condition:
sel /= table->field[fldno]->cond_selectivity;
Setting optimizer_switch='rowid_filter=off' does not help.
Most probably the bug can be reproduced in 10.1,10.2,10.3 with corresponding settings.
{"report":{"fcp":794.7000000476837,"ttfb":173.29999995231628,"pageVisibility":"visible","entityId":76969,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"c9a4475e-5ca9-4ab0-99a0-680467f1ec1f","navigationType":0,"readyForUser":881.5,"redirectCount":0,"resourceLoadedEnd":830.2000000476837,"resourceLoadedStart":179.40000009536743,"resourceTiming":[{"duration":12.699999809265137,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":179.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":179.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":192.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":12.700000047683716,"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":179.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":179.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":192.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":71.60000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":179.79999995231628,"connectEnd":179.79999995231628,"connectStart":179.79999995231628,"domainLookupEnd":179.79999995231628,"domainLookupStart":179.79999995231628,"fetchStart":179.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":179.79999995231628,"responseEnd":251.40000009536743,"responseStart":251.40000009536743,"secureConnectionStart":179.79999995231628},{"duration":149.5,"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":180.5,"connectEnd":180.5,"connectStart":180.5,"domainLookupEnd":180.5,"domainLookupStart":180.5,"fetchStart":180.5,"redirectEnd":0,"redirectStart":0,"requestStart":180.5,"responseEnd":330,"responseStart":329.90000009536743,"secureConnectionStart":180.5},{"duration":153.5,"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":180.79999995231628,"connectEnd":180.79999995231628,"connectStart":180.79999995231628,"domainLookupEnd":180.79999995231628,"domainLookupStart":180.79999995231628,"fetchStart":180.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":180.79999995231628,"responseEnd":334.2999999523163,"responseStart":334.2999999523163,"secureConnectionStart":180.79999995231628},{"duration":153.79999995231628,"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":181,"connectEnd":181,"connectStart":181,"domainLookupEnd":181,"domainLookupStart":181,"fetchStart":181,"redirectEnd":0,"redirectStart":0,"requestStart":181,"responseEnd":334.7999999523163,"responseStart":334.7999999523163,"secureConnectionStart":181},{"duration":154.20000004768372,"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":181.09999990463257,"connectEnd":181.09999990463257,"connectStart":181.09999990463257,"domainLookupEnd":181.09999990463257,"domainLookupStart":181.09999990463257,"fetchStart":181.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":181.09999990463257,"responseEnd":335.2999999523163,"responseStart":335.2999999523163,"secureConnectionStart":181.09999990463257},{"duration":223.89999985694885,"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":181.20000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":181.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":405.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":154.39999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":181.40000009536743,"connectEnd":181.40000009536743,"connectStart":181.40000009536743,"domainLookupEnd":181.40000009536743,"domainLookupStart":181.40000009536743,"fetchStart":181.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":181.40000009536743,"responseEnd":335.7999999523163,"responseStart":335.7999999523163,"secureConnectionStart":181.40000009536743},{"duration":223.60000014305115,"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":181.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":181.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":405.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":154.60000014305115,"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":181.79999995231628,"connectEnd":181.79999995231628,"connectStart":181.79999995231628,"domainLookupEnd":181.79999995231628,"domainLookupStart":181.79999995231628,"fetchStart":181.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":181.79999995231628,"responseEnd":336.40000009536743,"responseStart":336.40000009536743,"secureConnectionStart":181.79999995231628},{"duration":298.60000014305115,"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":182.59999990463257,"connectEnd":182.59999990463257,"connectStart":182.59999990463257,"domainLookupEnd":182.59999990463257,"domainLookupStart":182.59999990463257,"fetchStart":182.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":182.59999990463257,"responseEnd":481.2000000476837,"responseStart":481.2000000476837,"secureConnectionStart":182.59999990463257},{"duration":335,"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":182.70000004768372,"connectEnd":182.70000004768372,"connectStart":182.70000004768372,"domainLookupEnd":182.70000004768372,"domainLookupStart":182.70000004768372,"fetchStart":182.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":182.70000004768372,"responseEnd":517.7000000476837,"responseStart":517.7000000476837,"secureConnectionStart":182.70000004768372},{"duration":64.89999985694885,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":417.7000000476837,"connectEnd":417.7000000476837,"connectStart":417.7000000476837,"domainLookupEnd":417.7000000476837,"domainLookupStart":417.7000000476837,"fetchStart":417.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":417.7000000476837,"responseEnd":482.59999990463257,"responseStart":482.59999990463257,"secureConnectionStart":417.7000000476837},{"duration":45.59999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":701.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":701.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":746.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":121.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":702.2000000476837,"connectEnd":702.2000000476837,"connectStart":702.2000000476837,"domainLookupEnd":702.2000000476837,"domainLookupStart":702.2000000476837,"fetchStart":702.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":702.2000000476837,"responseEnd":824,"responseStart":824,"secureConnectionStart":702.2000000476837},{"duration":127.60000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":702.5999999046326,"connectEnd":702.5999999046326,"connectStart":702.5999999046326,"domainLookupEnd":702.5999999046326,"domainLookupStart":702.5999999046326,"fetchStart":702.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":702.5999999046326,"responseEnd":830.2000000476837,"responseStart":830.2000000476837,"secureConnectionStart":702.5999999046326},{"duration":139.90000009536743,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":787.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":787.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":927.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":167.90000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":810.2999999523163,"connectEnd":810.2999999523163,"connectStart":810.2999999523163,"domainLookupEnd":810.2999999523163,"domainLookupStart":810.2999999523163,"fetchStart":810.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":810.2999999523163,"responseEnd":978.2000000476837,"responseStart":978.2000000476837,"secureConnectionStart":810.2999999523163}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":16,"responseStart":173,"responseEnd":178,"domLoading":177,"domInteractive":967,"domContentLoadedEventStart":967,"domContentLoadedEventEnd":1012,"domComplete":1066,"loadEventStart":1066,"loadEventEnd":1066,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":929.9000000953674},{"name":"bigPipe.sidebar-id.end","time":930.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":930.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":932},{"name":"activityTabFullyLoaded","time":1033.9000000953674}],"measures":[],"correlationId":"2e2f015ad8a804","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":97,"dbReadsTimeInMs":10,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
http://lists.askmonty.org/pipermail/commits/2019-June/013885.html
Igor, please review