This test case is not working on MariaDB 10.1.3:
CREATE TABLE
|
test ( id INT, type_id INT, PRIMARY KEY(id) );
|
|
INSERT INTO
|
test ( id, type_id )
|
VALUES
|
( 1, 1 ),
|
( 2, 1 ),
|
( 3, 2 ),
|
( 4, 5 );
|
|
SELECT
|
*
|
FROM
|
test T
|
JOIN (
|
(
|
SELECT 1 AS some_another_type_id
|
)
|
UNION ALL
|
(
|
SELECT 2 AS some_another_type_id
|
)
|
ORDER BY
|
some_another_type_id DESC
|
) AAA
|
WHERE
|
T.type_id = 1;
|
Same query on clean Mysql 5.6 working with no problems.
Workaround: delete unneeded "order by".
{"report":{"fcp":1144.2999999523163,"ttfb":495.40000009536743,"pageVisibility":"visible","entityId":50526,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"eaf38f7b-1254-45ee-ad6d-6209708d9aff","navigationType":0,"readyForUser":1211.1000001430511,"redirectCount":0,"resourceLoadedEnd":1078.2999999523163,"resourceLoadedStart":499.7000000476837,"resourceTiming":[{"duration":181.20000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":499.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":499.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":680.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":181,"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":499.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":499.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":680.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":189.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":500,"connectEnd":500,"connectStart":500,"domainLookupEnd":500,"domainLookupStart":500,"fetchStart":500,"redirectEnd":0,"redirectStart":0,"requestStart":500,"responseEnd":689.9000000953674,"responseStart":689.9000000953674,"secureConnectionStart":500},{"duration":242.19999980926514,"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":500.10000014305115,"connectEnd":500.10000014305115,"connectStart":500.10000014305115,"domainLookupEnd":500.10000014305115,"domainLookupStart":500.10000014305115,"fetchStart":500.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":500.10000014305115,"responseEnd":742.2999999523163,"responseStart":742.2000000476837,"secureConnectionStart":500.10000014305115},{"duration":245.59999990463257,"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":500.2000000476837,"connectEnd":500.2000000476837,"connectStart":500.2000000476837,"domainLookupEnd":500.2000000476837,"domainLookupStart":500.2000000476837,"fetchStart":500.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":500.2000000476837,"responseEnd":745.7999999523163,"responseStart":745.7999999523163,"secureConnectionStart":500.2000000476837},{"duration":246,"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":500.2999999523163,"connectEnd":500.2999999523163,"connectStart":500.2999999523163,"domainLookupEnd":500.2999999523163,"domainLookupStart":500.2999999523163,"fetchStart":500.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":500.2999999523163,"responseEnd":746.2999999523163,"responseStart":746.2999999523163,"secureConnectionStart":500.2999999523163},{"duration":246.5,"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":500.40000009536743,"connectEnd":500.40000009536743,"connectStart":500.40000009536743,"domainLookupEnd":500.40000009536743,"domainLookupStart":500.40000009536743,"fetchStart":500.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":500.40000009536743,"responseEnd":746.9000000953674,"responseStart":746.9000000953674,"secureConnectionStart":500.40000009536743},{"duration":246.79999995231628,"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":500.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":500.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":747.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":246.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":500.60000014305115,"connectEnd":500.60000014305115,"connectStart":500.60000014305115,"domainLookupEnd":500.60000014305115,"domainLookupStart":500.60000014305115,"fetchStart":500.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":500.60000014305115,"responseEnd":747.2999999523163,"responseStart":747.2999999523163,"secureConnectionStart":500.60000014305115},{"duration":247,"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":500.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":500.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":747.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":247.10000014305115,"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":500.7999999523163,"connectEnd":500.7999999523163,"connectStart":500.7999999523163,"domainLookupEnd":500.7999999523163,"domainLookupStart":500.7999999523163,"fetchStart":500.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":500.7999999523163,"responseEnd":747.9000000953674,"responseStart":747.9000000953674,"secureConnectionStart":500.7999999523163},{"duration":491.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":506,"connectEnd":506,"connectStart":506,"domainLookupEnd":506,"domainLookupStart":506,"fetchStart":506,"redirectEnd":0,"redirectStart":0,"requestStart":506,"responseEnd":997.4000000953674,"responseStart":997.4000000953674,"secureConnectionStart":506},{"duration":571.3999998569489,"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":506.90000009536743,"connectEnd":506.90000009536743,"connectStart":506.90000009536743,"domainLookupEnd":506.90000009536743,"domainLookupStart":506.90000009536743,"fetchStart":506.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":506.90000009536743,"responseEnd":1078.2999999523163,"responseStart":1078.2999999523163,"secureConnectionStart":506.90000009536743},{"duration":175.89999985694885,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":902.1000001430511,"connectEnd":902.1000001430511,"connectStart":902.1000001430511,"domainLookupEnd":902.1000001430511,"domainLookupStart":902.1000001430511,"fetchStart":902.1000001430511,"redirectEnd":0,"redirectStart":0,"requestStart":902.1000001430511,"responseEnd":1078,"responseStart":1078,"secureConnectionStart":902.1000001430511},{"duration":80.29999995231628,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1084.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1084.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1165.2000000476837,"responseStart":0,"secureConnectionStart":0}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":57,"responseStart":496,"responseEnd":507,"domLoading":499,"domInteractive":1270,"domContentLoadedEventStart":1270,"domContentLoadedEventEnd":1313,"domComplete":1475,"loadEventStart":1475,"loadEventEnd":1475,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1247},{"name":"bigPipe.sidebar-id.end","time":1247.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":1248.1000001430511},{"name":"bigPipe.activity-panel-pipe-id.end","time":1249.7999999523163},{"name":"activityTabFullyLoaded","time":1327.9000000953674}],"measures":[],"correlationId":"d5c9bd1ca6af50","effectiveType":"4g","downlink":9.2,"rtt":0,"serverDuration":382,"dbReadsTimeInMs":11,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thanks for the report and the test case.
The problem appeared along with UNION ALL optimization:
commit 3c4bb0e8720b84a14fe4822d1986d01290b9ab44 fec5ab5a56cb9a45c621207620cc85079cddf537
Author: Igor Babaev <igor@askmonty.org>
Date: Tue Oct 14 09:36:50 2014 -0700
MDEV-334: Backport of UNION ALL optimization from mysql-5.7.
Although the original code of mysql-5.7 was adjusted
to the current MariaDB code the main ideas of the optimization
were preserved.
The same test case works all right on the current 5.7 tree.