Sergei Petrunia
added a comment - A reply to igor 's comment: https://jira.mariadb.org/browse/MDEV-26337?focusedCommentId=209666&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-209666
Ok so I create the tables described and fill them with data:
create table t1 (a int , b int , c int );
create table t2 (a int , b int , c int , key (a,b));
# 100 groups x 1K elements
insert into t2
select
A.seq,
B.seq,
C.seq
from
seq_0_to_9 A,
seq_0_to_9 B,
seq_0_to_999 C;
insert into t1 select
seq, seq, seq
from
seq_1_to_10;
Then, I run the provided query (adjusted it a bit to avoid syntax errors):
explain
select s from t1,
( select a,b, sum (c) as s
from t2 group by a,b) dt
where
t1.a=dt.a and
t1.b=dt.b and
t1.a in (1,3,5) and
t1.b between 2 and 4;
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------+
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 10 | Using where |
| 1 | PRIMARY | <derived2> | ref | key0 | key0 | 10 | j2.t1.a,j2.t1.b | 2 | |
| 2 | LATERAL DERIVED | t2 | ref | a | a | 10 | j2.t1.a,j2.t1.b | 1 | Using index condition |
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------+
Indeed, there's no sorting done.
But if I add WITH ROLLUP, I see that the subquery now uses "Using filesort":
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------------+
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 10 | Using where |
| 1 | PRIMARY | <derived2> | ref | key0 | key0 | 10 | j2.t1.a,j2.t1.b | 2 | |
| 2 | LATERAL DERIVED | t2 | ref | a | a | 10 | j2.t1.a,j2.t1.b | 1 | Using where; Using filesort |
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------------+
People
Sergei Petrunia
Sergei Petrunia
Votes:
0Vote for this issue
Watchers:
1Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":969.7999999523163,"ttfb":364.2000000476837,"pageVisibility":"visible","entityId":106747,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"a909c3f2-2a50-4cf0-8f95-03cc36e76c1a","navigationType":0,"readyForUser":1035.7000000476837,"redirectCount":0,"resourceLoadedEnd":970.2000000476837,"resourceLoadedStart":371.5,"resourceTiming":[{"duration":48.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":371.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":371.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":419.90000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":49.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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":371.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":371.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":421.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":86.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/c54b129276d75dc2a3460e1d78f37913-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":371.90000009536743,"connectEnd":371.90000009536743,"connectStart":371.90000009536743,"domainLookupEnd":371.90000009536743,"domainLookupStart":371.90000009536743,"fetchStart":371.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":428.5,"responseEnd":458.7000000476837,"responseStart":439.7999999523163,"secureConnectionStart":371.90000009536743},{"duration":287,"initiatorType":"script","name":"https://jira.mariadb.org/s/f867843cd2fdb209d4d1d4f760f86346-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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":371.90000009536743,"connectEnd":439.59999990463257,"connectStart":439.59999990463257,"domainLookupEnd":439.59999990463257,"domainLookupStart":439.59999990463257,"fetchStart":371.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":441.09999990463257,"responseEnd":658.9000000953674,"responseStart":453.59999990463257,"secureConnectionStart":439.59999990463257},{"duration":77.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/ffdb17665775c5b4d6f097f3974ee359-CDN/lu2bsh/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":372,"connectEnd":372,"connectStart":372,"domainLookupEnd":372,"domainLookupStart":372,"fetchStart":372,"redirectEnd":0,"redirectStart":0,"requestStart":430.90000009536743,"responseEnd":449.7999999523163,"responseStart":449,"secureConnectionStart":372},{"duration":85.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":372.09999990463257,"connectEnd":372.09999990463257,"connectStart":372.09999990463257,"domainLookupEnd":372.09999990463257,"domainLookupStart":372.09999990463257,"fetchStart":372.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":433.7999999523163,"responseEnd":457.90000009536743,"responseStart":457.40000009536743,"secureConnectionStart":372.09999990463257},{"duration":81.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":372.2000000476837,"connectEnd":372.2000000476837,"connectStart":372.2000000476837,"domainLookupEnd":372.2000000476837,"domainLookupStart":372.2000000476837,"fetchStart":372.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":441.40000009536743,"responseEnd":453.5,"responseStart":452.2999999523163,"secureConnectionStart":372.2000000476837},{"duration":68.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bsh/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":372.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":372.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":440.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":110.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":372.40000009536743,"connectEnd":372.40000009536743,"connectStart":372.40000009536743,"domainLookupEnd":372.40000009536743,"domainLookupStart":372.40000009536743,"fetchStart":372.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":450.2000000476837,"responseEnd":482.5,"responseStart":481,"secureConnectionStart":372.40000009536743},{"duration":73.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bsh/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":372.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":372.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":446,"responseStart":0,"secureConnectionStart":0},{"duration":96.20000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/81b5d7c27af3ebc078cc4a36383678ba-CDN/lu2bsh/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":372.59999990463257,"connectEnd":372.59999990463257,"connectStart":372.59999990463257,"domainLookupEnd":372.59999990463257,"domainLookupStart":372.59999990463257,"fetchStart":372.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":451.7000000476837,"responseEnd":468.7999999523163,"responseStart":466.5,"secureConnectionStart":372.59999990463257},{"duration":376.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":381.40000009536743,"connectEnd":381.40000009536743,"connectStart":381.40000009536743,"domainLookupEnd":381.40000009536743,"domainLookupStart":381.40000009536743,"fetchStart":381.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":711.2000000476837,"responseEnd":757.9000000953674,"responseStart":755.2999999523163,"secureConnectionStart":381.40000009536743},{"duration":583.7000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":386.5,"connectEnd":386.5,"connectStart":386.5,"domainLookupEnd":386.5,"domainLookupStart":386.5,"fetchStart":386.5,"redirectEnd":0,"redirectStart":0,"requestStart":958.2999999523163,"responseEnd":970.2000000476837,"responseStart":969.2000000476837,"secureConnectionStart":386.5},{"duration":153.29999995231628,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":595.2000000476837,"connectEnd":595.2000000476837,"connectStart":595.2000000476837,"domainLookupEnd":595.2000000476837,"domainLookupStart":595.2000000476837,"fetchStart":595.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":714.5999999046326,"responseEnd":748.5,"responseStart":746.7999999523163,"secureConnectionStart":595.2000000476837},{"duration":115.79999995231628,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":891.2000000476837,"connectEnd":891.2000000476837,"connectStart":891.2000000476837,"domainLookupEnd":891.2000000476837,"domainLookupStart":891.2000000476837,"fetchStart":891.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":974.5,"responseEnd":1007,"responseStart":1006.2000000476837,"secureConnectionStart":891.2000000476837}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":242,"responseStart":364,"responseEnd":386,"domLoading":367,"domInteractive":1094,"domContentLoadedEventStart":1094,"domContentLoadedEventEnd":1142,"domComplete":1328,"loadEventStart":1328,"loadEventEnd":1328,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1067.2000000476837},{"name":"bigPipe.sidebar-id.end","time":1067.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":1068.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":1070.5},{"name":"activityTabFullyLoaded","time":1159.2000000476837}],"measures":[],"correlationId":"7dce4a2ca91a67","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":70,"dbReadsTimeInMs":12,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
A reply to igor's comment: https://jira.mariadb.org/browse/MDEV-26337?focusedCommentId=209666&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-209666
Ok so I create the tables described and fill them with data:
# 100 groups x 1K elements
select
A.seq,
B.seq,
C.seq
seq_0_to_9 A,
seq_0_to_9 B,
seq_0_to_999 C;
seq, seq, seq
from
seq_1_to_10;
Then, I run the provided query (adjusted it a bit to avoid syntax errors):
explain
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------+
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 10 | Using where |
| 1 | PRIMARY | <derived2> | ref | key0 | key0 | 10 | j2.t1.a,j2.t1.b | 2 | |
| 2 | LATERAL DERIVED | t2 | ref | a | a | 10 | j2.t1.a,j2.t1.b | 1 | Using index condition |
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------+
Indeed, there's no sorting done.
But if I add WITH ROLLUP, I see that the subquery now uses "Using filesort":
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------------+
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 10 | Using where |
| 1 | PRIMARY | <derived2> | ref | key0 | key0 | 10 | j2.t1.a,j2.t1.b | 2 | |
| 2 | LATERAL DERIVED | t2 | ref | a | a | 10 | j2.t1.a,j2.t1.b | 1 | Using where; Using filesort |
+------+-----------------+------------+------+---------------+------+---------+-----------------+------+-----------------------------+