-
Task
-
-
Critical
-
Resolution:
Unresolved
-
None
-
-
Selectivity computations can produce poor estimates when multi-part keys are involved.
Motivating example:
create table t1 (
|
id int auto_increment primary key,
|
a int,
|
b int,
|
f varchar(256) default 'xxx',
|
index idx1(a),
|
index idx2(b)
|
);
|
insert into t1(a,b) select rand(13) * 1000 mod 200, rand(17) * 1000 mod 50 from seq_1_to_1000;
|
create index idx3 on t1(a,b);
|
# Use query plans that are easier to read:
|
set optimizer_switch='rowid_filter=off';
|
First, let's use single-column indexes only:
explain extended select * from t1 ignore index (idx3)
|
where a between 50 and 80 and b between 33 and 41;
|
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+------------------------------------+
|
| 1 | SIMPLE | t1 | range | idx1,idx2 | idx1 | 5 | NULL | 149 | 17.50 | Using index condition; Using where |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+----------+------------------------------------+
|
The estimated #rows in the output is 149 * 0.175= 26 rows.
The estimates are obtained from
"range_scan_alternatives": [
|
{
|
"index": "idx1",
|
"ranges": ["(50) <= (a) <= (80)"],
|
"rowid_ordered": false,
|
"using_mrr": false,
|
"index_only": false,
|
"rows": 149,
|
"cost": 0.1537364,
|
"chosen": true
|
},
|
{
|
"index": "idx2",
|
"ranges": ["(33) <= (b) <= (41)"],
|
"rowid_ordered": false,
|
"using_mrr": false,
|
"index_only": false,
|
"rows": 175,
|
"cost": 0.17956584,
|
"chosen": false,
|
"cause": "cost"
|
}
|
Now, with three indexes:
explain extended select * from t1 where a between 50 and 80 and b between 33 and 41;
|
+------+-------------+-------+-------+----------------+------+---------+------+------+----------+-----------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+-------+----------------+------+---------+------+------+----------+-----------------------+
|
| 1 | SIMPLE | t1 | range | idx1,idx2,idx3 | idx3 | 10 | NULL | 144 | 100.00 | Using index condition |
|
+------+-------------+-------+-------+----------------+------+---------+------+------+----------+-----------------------+
|
It is using this plan
"chosen_range_access_summary": {
|
"range_access_plan": {
|
"type": "range_scan",
|
"index": "idx3",
|
"rows": 144,
|
"ranges": ["(50,33) <= (a,b) <= (80,41)"]
|
},
|
"rows_for_plan": 144,
|
"cost_for_plan": 0.1487692,
|
"chosen": true
|
}
|
It has these estimate numbers at its disposal:
"range_scan_alternatives": [
|
{
|
"index": "idx1",
|
"ranges": ["(50) <= (a) <= (80)"],
|
"rowid_ordered": false,
|
"using_mrr": false,
|
"index_only": false,
|
"rows": 149,
|
"cost": 0.1537364,
|
"chosen": true
|
},
|
{
|
"index": "idx2",
|
"ranges": ["(33) <= (b) <= (41)"],
|
"rowid_ordered": false,
|
"using_mrr": false,
|
"index_only": false,
|
"rows": 175,
|
"cost": 0.17956584,
|
"chosen": false,
|
"cause": "cost"
|
},
|
{
|
"index": "idx3",
|
"ranges": ["(50,33) <= (a,b) <= (80,41)"],
|
"rowid_ordered": false,
|
"using_mrr": false,
|
"index_only": false,
|
"rows": 144,
|
"cost": 0.1487692,
|
"chosen": true
|
}
|
],
|
and the point is that it could come up with a tighter estimate of output bound by taking into account the estimates on a and b separately.
Igor's point is that "keyparts >=1 do not matter for non-equalities".
- is part of
-
MDEV-23707
Fix condition selectivity computation for join prefixes
-
-
Stalled
{"report":{"fcp":2057.800000190735,"ttfb":664.4000000953674,"pageVisibility":"visible","entityId":128392,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"95f16cea-aaf1-4724-933d-1be0175485c3","navigationType":0,"readyForUser":2181.800000190735,"redirectCount":0,"resourceLoadedEnd":2267.600000143051,"resourceLoadedStart":674.4000000953674,"resourceTiming":[{"duration":857.0999999046326,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":674.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":674.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1531.5,"responseStart":0,"secureConnectionStart":0},{"duration":857.2999999523163,"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":674.6000001430511,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":674.6000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1531.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":865.8999998569489,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":674.8000001907349,"connectEnd":674.8000001907349,"connectStart":674.8000001907349,"domainLookupEnd":674.8000001907349,"domainLookupStart":674.8000001907349,"fetchStart":674.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":674.8000001907349,"responseEnd":1540.7000000476837,"responseStart":1540.7000000476837,"secureConnectionStart":674.8000001907349},{"duration":949.4000000953674,"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":675,"connectEnd":675,"connectStart":675,"domainLookupEnd":675,"domainLookupStart":675,"fetchStart":675,"redirectEnd":0,"redirectStart":0,"requestStart":675,"responseEnd":1624.4000000953674,"responseStart":1624.4000000953674,"secureConnectionStart":675},{"duration":953.3999998569489,"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":675.3000001907349,"connectEnd":675.3000001907349,"connectStart":675.3000001907349,"domainLookupEnd":675.3000001907349,"domainLookupStart":675.3000001907349,"fetchStart":675.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":675.3000001907349,"responseEnd":1628.7000000476837,"responseStart":1628.7000000476837,"secureConnectionStart":675.3000001907349},{"duration":953.9000000953674,"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":675.5,"connectEnd":675.5,"connectStart":675.5,"domainLookupEnd":675.5,"domainLookupStart":675.5,"fetchStart":675.5,"redirectEnd":0,"redirectStart":0,"requestStart":675.5,"responseEnd":1629.4000000953674,"responseStart":1629.4000000953674,"secureConnectionStart":675.5},{"duration":954.5,"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":675.6000001430511,"connectEnd":675.6000001430511,"connectStart":675.6000001430511,"domainLookupEnd":675.6000001430511,"domainLookupStart":675.6000001430511,"fetchStart":675.6000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":675.6000001430511,"responseEnd":1630.1000001430511,"responseStart":1630.1000001430511,"secureConnectionStart":675.6000001430511},{"duration":1012.8999998569489,"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":675.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":675.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1688.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":954.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":676,"connectEnd":676,"connectStart":676,"domainLookupEnd":676,"domainLookupStart":676,"fetchStart":676,"redirectEnd":0,"redirectStart":0,"requestStart":676,"responseEnd":1630.7000000476837,"responseStart":1630.7000000476837,"secureConnectionStart":676},{"duration":1012.7999999523163,"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":676.1000001430511,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":676.1000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1688.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":954.9000000953674,"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":676.4000000953674,"connectEnd":676.4000000953674,"connectStart":676.4000000953674,"domainLookupEnd":676.4000000953674,"domainLookupStart":676.4000000953674,"fetchStart":676.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":676.4000000953674,"responseEnd":1631.3000001907349,"responseStart":1631.3000001907349,"secureConnectionStart":676.4000000953674},{"duration":1296.5999999046326,"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":689.4000000953674,"connectEnd":689.4000000953674,"connectStart":689.4000000953674,"domainLookupEnd":689.4000000953674,"domainLookupStart":689.4000000953674,"fetchStart":689.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":689.4000000953674,"responseEnd":1986,"responseStart":1986,"secureConnectionStart":689.4000000953674},{"duration":1574.5999999046326,"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":689.6000001430511,"connectEnd":689.6000001430511,"connectStart":689.6000001430511,"domainLookupEnd":689.6000001430511,"domainLookupStart":689.6000001430511,"fetchStart":689.6000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":689.6000001430511,"responseEnd":2264.2000000476837,"responseStart":2264.2000000476837,"secureConnectionStart":689.6000001430511},{"duration":284.7000000476837,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1701.7000000476837,"connectEnd":1701.7000000476837,"connectStart":1701.7000000476837,"domainLookupEnd":1701.7000000476837,"domainLookupStart":1701.7000000476837,"fetchStart":1701.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":1701.7000000476837,"responseEnd":1986.4000000953674,"responseStart":1986.4000000953674,"secureConnectionStart":1701.7000000476837},{"duration":262,"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":2003.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":2003.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2265.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":261,"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":2004.3000001907349,"connectEnd":2004.3000001907349,"connectStart":2004.3000001907349,"domainLookupEnd":2004.3000001907349,"domainLookupStart":2004.3000001907349,"fetchStart":2004.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":2004.3000001907349,"responseEnd":2265.300000190735,"responseStart":2265.2000000476837,"secureConnectionStart":2004.3000001907349},{"duration":262.90000009536743,"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":2004.7000000476837,"connectEnd":2004.7000000476837,"connectStart":2004.7000000476837,"domainLookupEnd":2004.7000000476837,"domainLookupStart":2004.7000000476837,"fetchStart":2004.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":2004.7000000476837,"responseEnd":2267.600000143051,"responseStart":2267.5,"secureConnectionStart":2004.7000000476837},{"duration":262.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":2048.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":2048.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2310.9000000953674,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":472,"responseStart":664,"responseEnd":675,"domLoading":668,"domInteractive":2363,"domContentLoadedEventStart":2363,"domContentLoadedEventEnd":2428,"domComplete":2787,"loadEventStart":2787,"loadEventEnd":2788,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2316},{"name":"bigPipe.sidebar-id.end","time":2317.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":2317.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":2321.2000000476837},{"name":"activityTabFullyLoaded","time":2448.100000143051}],"measures":[],"correlationId":"bea6e4fdac9c9","effectiveType":"4g","downlink":9.2,"rtt":0,"serverDuration":114,"dbReadsTimeInMs":21,"dbConnsTimeInMs":30,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}