Type:
Bug
Priority:
Minor
Resolution:
Unresolved
Affects Version/s:
10.6
The optimization of MDEV-30660 is performed too late to affect some of the optimizer choices:
create table t1 (
pk1 int ,
pk2 int ,
filler char (100),
primary key (pk1, pk2)
);
insert into t1 select seq, seq, seq from seq_1_to_10000;
MariaDB [test]> explain select count(distinct pk1) from t1 group by pk2 order by null;
+------+-------------+-------+-------+---------------+---------+---------+------+-------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+-------+---------------+---------+---------+------+-------+-----------------------------+
| 1 | SIMPLE | t1 | index | NULL | PRIMARY | 8 | NULL | 10030 | Using index; Using filesort |
+------+-------------+-------+-------+---------------+---------+---------+------+-------+-----------------------------+
1 row in set (0.000 sec)
Optimizer Trace shows that DISTINCT was removed:
{
"prepare_sum_aggregators": {
"function": "count(distinct t1.pk1)",
"aggregator_type": "simple"
}
}
but note the "Using filesort" in EXPLAIN output^^.
It is present, because the GROUP BY optimization was preparing to use COUNT-DISTINCT which requires that one GROUP BY group is processed after another...
If I remove DISTINCT manually, the query won't use sorting:
MariaDB [test]> explain select count(pk1) from t1 group by pk2 order by null;
+------+-------------+-------+-------+---------------+---------+---------+------+-------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+-------+---------------+---------+---------+------+-------+------------------------------+
| 1 | SIMPLE | t1 | index | NULL | PRIMARY | 8 | NULL | 10030 | Using index; Using temporary |
+------+-------------+-------+-------+---------------+---------+---------+------+-------+------------------------------+
relates to
MDEV-30660
Aggregation functions fail to leverage uniqueness property
Closed
There are no comments yet on this issue.
{"report":{"fcp":780.3999998569489,"ttfb":200.70000004768372,"pageVisibility":"visible","entityId":128739,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"9c0bfc2d-ca5c-4048-99e3-3cbde5b3966c","navigationType":0,"readyForUser":878,"redirectCount":0,"resourceLoadedEnd":520,"resourceLoadedStart":210.09999990463257,"resourceTiming":[{"duration":53.299999952316284,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":210.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":210.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":263.39999985694885,"responseStart":0,"secureConnectionStart":0},{"duration":53.10000014305115,"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":211.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":211.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":264.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":187.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":211.20000004768372,"connectEnd":211.20000004768372,"connectStart":211.20000004768372,"domainLookupEnd":211.20000004768372,"domainLookupStart":211.20000004768372,"fetchStart":211.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":266,"responseEnd":398.5,"responseStart":283.89999985694885,"secureConnectionStart":211.20000004768372},{"duration":100.40000009536743,"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":211.79999995231628,"connectEnd":211.79999995231628,"connectStart":211.79999995231628,"domainLookupEnd":211.79999995231628,"domainLookupStart":211.79999995231628,"fetchStart":211.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":267.2000000476837,"responseEnd":312.2000000476837,"responseStart":310.89999985694885,"secureConnectionStart":211.79999995231628},{"duration":298.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":211.79999995231628,"connectEnd":211.79999995231628,"connectStart":211.79999995231628,"domainLookupEnd":211.79999995231628,"domainLookupStart":211.79999995231628,"fetchStart":211.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":266.7000000476837,"responseEnd":510.39999985694885,"responseStart":305.2999999523163,"secureConnectionStart":211.79999995231628},{"duration":101.19999980926514,"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":212.70000004768372,"connectEnd":212.70000004768372,"connectStart":212.70000004768372,"domainLookupEnd":212.70000004768372,"domainLookupStart":212.70000004768372,"fetchStart":212.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":267.89999985694885,"responseEnd":313.89999985694885,"responseStart":312.39999985694885,"secureConnectionStart":212.70000004768372},{"duration":54.80000019073486,"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":212.89999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":212.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":267.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":77,"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":212.89999985694885,"connectEnd":212.89999985694885,"connectStart":212.89999985694885,"domainLookupEnd":212.89999985694885,"domainLookupStart":212.89999985694885,"fetchStart":212.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":275.2999999523163,"responseEnd":289.89999985694885,"responseStart":288.7000000476837,"secureConnectionStart":212.89999985694885},{"duration":66.10000014305115,"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":213.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":213.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":279.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":91.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":213.09999990463257,"connectEnd":213.09999990463257,"connectStart":213.09999990463257,"domainLookupEnd":213.09999990463257,"domainLookupStart":213.09999990463257,"fetchStart":213.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":280.09999990463257,"responseEnd":304.89999985694885,"responseStart":303.39999985694885,"secureConnectionStart":213.09999990463257},{"duration":114.69999980926514,"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":213.20000004768372,"connectEnd":213.20000004768372,"connectStart":213.20000004768372,"domainLookupEnd":213.20000004768372,"domainLookupStart":213.20000004768372,"fetchStart":213.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":281.7000000476837,"responseEnd":327.89999985694885,"responseStart":324.2999999523163,"secureConnectionStart":213.20000004768372},{"duration":301.40000009536743,"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":218.39999985694885,"connectEnd":218.39999985694885,"connectStart":218.39999985694885,"domainLookupEnd":218.39999985694885,"domainLookupStart":218.39999985694885,"fetchStart":218.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":432,"responseEnd":519.7999999523163,"responseStart":515.8999998569489,"secureConnectionStart":218.39999985694885},{"duration":301.60000014305115,"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":218.39999985694885,"connectEnd":218.39999985694885,"connectStart":218.39999985694885,"domainLookupEnd":218.39999985694885,"domainLookupStart":218.39999985694885,"fetchStart":218.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":432.59999990463257,"responseEnd":520,"responseStart":516.5999999046326,"secureConnectionStart":218.39999985694885},{"duration":190.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":534.2999999523163,"connectEnd":534.2999999523163,"connectStart":534.2999999523163,"domainLookupEnd":534.2999999523163,"domainLookupStart":534.2999999523163,"fetchStart":534.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":692.3999998569489,"responseEnd":724.7999999523163,"responseStart":724.2999999523163,"secureConnectionStart":534.2999999523163},{"duration":115.70000004768372,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":773.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":773.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":888.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":181.39999985694885,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":795.7000000476837,"connectEnd":795.7000000476837,"connectStart":795.7000000476837,"domainLookupEnd":795.7000000476837,"domainLookupStart":795.7000000476837,"fetchStart":795.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":947.5999999046326,"responseEnd":977.0999999046326,"responseStart":976.3999998569489,"secureConnectionStart":795.7000000476837}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":52,"responseStart":201,"responseEnd":217,"domLoading":204,"domInteractive":977,"domContentLoadedEventStart":977,"domContentLoadedEventEnd":1023,"domComplete":1307,"loadEventStart":1307,"loadEventEnd":1307,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":959.5},{"name":"bigPipe.sidebar-id.end","time":960.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":960.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":961.0999999046326},{"name":"activityTabFullyLoaded","time":1036.3999998569489}],"measures":[],"correlationId":"1202e2a784f613","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":83,"dbReadsTimeInMs":11,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}