create table ten(a int);
|
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
create table t1(key1 int, col1 int, key(key1));
|
insert into t1 select A.a, A.a from ten A, ten B, ten C;
|
|
set histogram_size=100;
|
set use_stat_tables='preferably';
|
set optimizer_use_condition_selectivity=4;
|
analyze table t1 persistent for all;
|
mysql> explain extended select * from t1 where col1=2;
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 1000 | 9.90 | Using where |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
|
This is ok.
mysql> explain extended select * from t1 where key1=2;
|
+------+-------------+-------+------+---------------+------+---------+-------+------+----------+-------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+------+---------------+------+---------+-------+------+----------+-------+
|
| 1 | SIMPLE | t1 | ref | key1 | key1 | 5 | const | 100 | 10.00 | |
|
+------+-------------+-------+------+---------------+------+---------+-------+------+----------+-------+
|
This is not ok. "key1=2" is used for ref access. However, its selectivity is still present in "filtered%". Ref access is employed when a condition is very selective, counting its selectivity twice will cause gross under-estimation of output cardinality.
{"report":{"fcp":1038.6999998092651,"ttfb":199.59999990463257,"pageVisibility":"visible","entityId":34002,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"d7ee48dd-4235-416d-9015-443b9ac461f8","navigationType":0,"readyForUser":1150.3000001907349,"redirectCount":0,"resourceLoadedEnd":1058,"resourceLoadedStart":206.30000019073486,"resourceTiming":[{"duration":291.7999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":206.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":206.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":498.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":291.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":206.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":206.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":498.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":346.1000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":206.69999980926514,"connectEnd":206.69999980926514,"connectStart":206.69999980926514,"domainLookupEnd":206.69999980926514,"domainLookupStart":206.69999980926514,"fetchStart":206.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":206.69999980926514,"responseEnd":552.8000001907349,"responseStart":552.8000001907349,"secureConnectionStart":206.69999980926514},{"duration":476.7999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":206.90000009536743,"connectEnd":206.90000009536743,"connectStart":206.90000009536743,"domainLookupEnd":206.90000009536743,"domainLookupStart":206.90000009536743,"fetchStart":206.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":206.90000009536743,"responseEnd":683.6999998092651,"responseStart":683.6999998092651,"secureConnectionStart":206.90000009536743},{"duration":480.30000019073486,"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":207.19999980926514,"connectEnd":207.19999980926514,"connectStart":207.19999980926514,"domainLookupEnd":207.19999980926514,"domainLookupStart":207.19999980926514,"fetchStart":207.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":207.19999980926514,"responseEnd":687.5,"responseStart":687.5,"secureConnectionStart":207.19999980926514},{"duration":480.59999990463257,"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":207.30000019073486,"connectEnd":207.30000019073486,"connectStart":207.30000019073486,"domainLookupEnd":207.30000019073486,"domainLookupStart":207.30000019073486,"fetchStart":207.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":207.30000019073486,"responseEnd":687.9000000953674,"responseStart":687.9000000953674,"secureConnectionStart":207.30000019073486},{"duration":480.69999980926514,"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":207.5,"connectEnd":207.5,"connectStart":207.5,"domainLookupEnd":207.5,"domainLookupStart":207.5,"fetchStart":207.5,"redirectEnd":0,"redirectStart":0,"requestStart":207.5,"responseEnd":688.1999998092651,"responseStart":688.1999998092651,"secureConnectionStart":207.5},{"duration":487.6000003814697,"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":207.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":207.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":695.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":481,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":207.80000019073486,"connectEnd":207.80000019073486,"connectStart":207.80000019073486,"domainLookupEnd":207.80000019073486,"domainLookupStart":207.80000019073486,"fetchStart":207.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":207.80000019073486,"responseEnd":688.8000001907349,"responseStart":688.8000001907349,"secureConnectionStart":207.80000019073486},{"duration":487.5,"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":207.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":207.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":695.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":481.30000019073486,"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":208.09999990463257,"connectEnd":208.09999990463257,"connectStart":208.09999990463257,"domainLookupEnd":208.09999990463257,"domainLookupStart":208.09999990463257,"fetchStart":208.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":208.09999990463257,"responseEnd":689.4000000953674,"responseStart":689.4000000953674,"secureConnectionStart":208.09999990463257},{"duration":553,"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":208.90000009536743,"connectEnd":208.90000009536743,"connectStart":208.90000009536743,"domainLookupEnd":208.90000009536743,"domainLookupStart":208.90000009536743,"fetchStart":208.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":208.90000009536743,"responseEnd":761.9000000953674,"responseStart":761.9000000953674,"secureConnectionStart":208.90000009536743},{"duration":687.9000000953674,"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":209,"connectEnd":209,"connectStart":209,"domainLookupEnd":209,"domainLookupStart":209,"fetchStart":209,"redirectEnd":0,"redirectStart":0,"requestStart":209,"responseEnd":896.9000000953674,"responseStart":896.9000000953674,"secureConnectionStart":209},{"duration":59,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":706.8000001907349,"connectEnd":706.8000001907349,"connectStart":706.8000001907349,"domainLookupEnd":706.8000001907349,"domainLookupStart":706.8000001907349,"fetchStart":706.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":706.8000001907349,"responseEnd":765.8000001907349,"responseStart":765.8000001907349,"secureConnectionStart":706.8000001907349},{"duration":85.80000019073486,"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","startTime":972.1999998092651,"connectEnd":972.1999998092651,"connectStart":972.1999998092651,"domainLookupEnd":972.1999998092651,"domainLookupStart":972.1999998092651,"fetchStart":972.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":972.1999998092651,"responseEnd":1058,"responseStart":1058,"secureConnectionStart":972.1999998092651},{"duration":150.30000019073486,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1031.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1031.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1181.9000000953674,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":33,"responseStart":200,"responseEnd":202,"domLoading":204,"domInteractive":1214,"domContentLoadedEventStart":1214,"domContentLoadedEventEnd":1269,"domComplete":1470,"loadEventStart":1470,"loadEventEnd":1471,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1184.1999998092651},{"name":"bigPipe.sidebar-id.end","time":1185.1999998092651},{"name":"bigPipe.activity-panel-pipe-id.start","time":1185.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":1187.4000000953674},{"name":"activityTabFullyLoaded","time":1283.9000000953674}],"measures":[],"correlationId":"af18c20e904b9c","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":100,"dbReadsTimeInMs":12,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
We should recongize it as an equality that was bound by ref and so discount its
selectivity (the selectivity comes from ... range... how do we figure out that
ref-bound equality has contributed as a possible range scan?)
Idea: keep array of induced selectivity
table->added_selectivity[field_no] = 0.123456
and if $field_no is used for ref access, than it's not contributing to
selectivity, and we remove its selectivity from the product.
Q: what to do about range accesses that span multiple key parts? It's not
possible to remove one key part from selectivity calculations...