For the following query
(select a from t1 limit 2) order by a desc
|
EXPLAIN shows
MariaDB [test]> explain (select a from t1 limit 2) order by a desc;
|
+------+-------------+-------+------+---------------+------+---------+------+------+-------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+-------+
|
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 3 | |
|
+------+-------------+-------+------+---------------+------+---------+------+------+-------+
|
though the execution of the query in debugger clearly indicates that first a temporary table is created for (select a from t1 limit 2) then the rows from this temporary are sorted.
So the expected output from EXPLAIN would be
MariaDB [test]> explain (select a from t1 limit 2) order by a desc;
|
+------+--------------+----------+------+---------------+------+---------+------+------+----------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+--------------+----------+------+---------------+------+---------+------+------+----------------+
|
| 1 | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | 3 | |
|
| NULL | UNION RESULT | <union1> | ALL | NULL | NULL | NULL | NULL | NULL | Using filesort |
|
+------+--------------+----------+------+---------------+------+---------+------+------+----------------+
|
The full test case is:
create table t1 (a int);
|
insert into t1 values (3), (7), (1);
|
explain (select a from t1 limit 2) order by a desc;
|
drop table t1;
|
{"report":{"fcp":767,"ttfb":205.70000004768372,"pageVisibility":"visible","entityId":99674,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"8df8bf91-be02-4050-8389-18e66b9066ac","navigationType":0,"readyForUser":843.5,"redirectCount":0,"resourceLoadedEnd":576.0999999046326,"resourceLoadedStart":213.29999995231628,"resourceTiming":[{"duration":43,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":213.29999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":213.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":256.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":42.69999980926514,"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":213.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":213.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":256.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":128.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":214,"connectEnd":214,"connectStart":214,"domainLookupEnd":214,"domainLookupStart":214,"fetchStart":214,"redirectEnd":0,"redirectStart":0,"requestStart":259.40000009536743,"responseEnd":342.09999990463257,"responseStart":272,"secureConnectionStart":214},{"duration":286.40000009536743,"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":214.09999990463257,"connectEnd":214.09999990463257,"connectStart":214.09999990463257,"domainLookupEnd":214.09999990463257,"domainLookupStart":214.09999990463257,"fetchStart":214.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":261.90000009536743,"responseEnd":500.5,"responseStart":277.09999990463257,"secureConnectionStart":214.09999990463257},{"duration":64.20000004768372,"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":214.20000004768372,"connectEnd":214.20000004768372,"connectStart":214.20000004768372,"domainLookupEnd":214.20000004768372,"domainLookupStart":214.20000004768372,"fetchStart":214.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":263.5,"responseEnd":278.40000009536743,"responseStart":276.40000009536743,"secureConnectionStart":214.20000004768372},{"duration":68,"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":214.29999995231628,"connectEnd":214.29999995231628,"connectStart":214.29999995231628,"domainLookupEnd":214.29999995231628,"domainLookupStart":214.29999995231628,"fetchStart":214.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":264.7000000476837,"responseEnd":282.2999999523163,"responseStart":280.90000009536743,"secureConnectionStart":214.29999995231628},{"duration":69.89999985694885,"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":214.40000009536743,"connectEnd":214.40000009536743,"connectStart":214.40000009536743,"domainLookupEnd":214.40000009536743,"domainLookupStart":214.40000009536743,"fetchStart":214.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":266.5,"responseEnd":284.2999999523163,"responseStart":283.2000000476837,"secureConnectionStart":214.40000009536743},{"duration":50.40000009536743,"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":214.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":214.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":265,"responseStart":0,"secureConnectionStart":0},{"duration":71.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":214.70000004768372,"connectEnd":214.70000004768372,"connectStart":214.70000004768372,"domainLookupEnd":214.70000004768372,"domainLookupStart":214.70000004768372,"fetchStart":214.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":268.2999999523163,"responseEnd":286.2000000476837,"responseStart":285,"secureConnectionStart":214.70000004768372},{"duration":52.299999952316284,"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":214.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":214.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":267.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":76.09999990463257,"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":214.90000009536743,"connectEnd":214.90000009536743,"connectStart":214.90000009536743,"domainLookupEnd":214.90000009536743,"domainLookupStart":214.90000009536743,"fetchStart":214.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":271.59999990463257,"responseEnd":291,"responseStart":289.59999990463257,"secureConnectionStart":214.90000009536743},{"duration":299.5,"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":227.29999995231628,"connectEnd":227.29999995231628,"connectStart":227.29999995231628,"domainLookupEnd":227.29999995231628,"domainLookupStart":227.29999995231628,"fetchStart":227.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":368.40000009536743,"responseEnd":526.7999999523163,"responseStart":521.9000000953674,"secureConnectionStart":227.29999995231628},{"duration":348.69999980926514,"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":227.40000009536743,"connectEnd":227.40000009536743,"connectStart":227.40000009536743,"domainLookupEnd":227.40000009536743,"domainLookupStart":227.40000009536743,"fetchStart":227.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":565.5,"responseEnd":576.0999999046326,"responseStart":575.2999999523163,"secureConnectionStart":227.40000009536743},{"duration":132.79999995231628,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":472.5,"connectEnd":472.5,"connectStart":472.5,"domainLookupEnd":472.5,"domainLookupStart":472.5,"fetchStart":472.5,"redirectEnd":0,"redirectStart":0,"requestStart":572.7999999523163,"responseEnd":605.2999999523163,"responseStart":604.5999999046326,"secureConnectionStart":472.5},{"duration":178.69999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":721.4000000953674,"connectEnd":721.4000000953674,"connectStart":721.4000000953674,"domainLookupEnd":721.4000000953674,"domainLookupStart":721.4000000953674,"fetchStart":721.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":868.2000000476837,"responseEnd":900.0999999046326,"responseStart":899.5,"secureConnectionStart":721.4000000953674},{"duration":133.10000014305115,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":760.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":760.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":893.2000000476837,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":30,"domainLookupEnd":39,"connectStart":39,"connectEnd":58,"secureConnectionStart":47,"requestStart":59,"responseStart":205,"responseEnd":226,"domLoading":209,"domInteractive":946,"domContentLoadedEventStart":946,"domContentLoadedEventEnd":995,"domComplete":1109,"loadEventStart":1109,"loadEventEnd":1110,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":917.4000000953674},{"name":"bigPipe.sidebar-id.end","time":918.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":918.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":920.2999999523163},{"name":"activityTabFullyLoaded","time":1014}],"measures":[],"correlationId":"80f4d6f6ff9eee","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":86,"dbReadsTimeInMs":10,"dbConnsTimeInMs":17,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
This is another test case that produces a wrong explain:
MariaDB [test]> explain (select b,a from t2 order by a limit 3) order by b desc;
+------+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | 4 | Using filesort |
+------+-------------+-------+------+---------------+------+---------+------+------+----------------+