Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
10.3.9 , 10.3.10 , 10.2(EOL) , 10.3(EOL) , 10.4(EOL) , 10.5
Environment:
Windows 64bit
A SELECT from a subquery containing a UNION with inconsistent result column names fails with an ill-fitting error message, but only when used with a WHERE clause.
This is a heavily striped down version of a query that fails:
select * from (
select 1 x
union all
select sum(1) y
) t where x>0
yields: ERROR 1054 (42S22): Unknown column 'x' in 'order clause'
which is strange, because there is no order clause.
This slightly different statement, however, works fine:
select * from (
select 1 x
union all
select 2 y
) t where x>0
(Note: second branch of UNION has no aggregate function)
and yields, as expected:
+---+
| x |
+---+
| 1 |
| 2 |
+---+
Omitting the WHERE clause from the first query allows it to succeed, too.
This seems to be a regression. My original query (much longer) used to work with an older 10.x version, but I cannot reconstruct any more which version that was.
On an old MySQL server 5.7.9, the problem does NOT come up. SQLite also has NO problems with the query, so I assume the query is legal as such, even given the inconsistent naming of columns.
Of course, a workaround is easy: use consistent aliases:
select * from (
select 1 x
union all
select sum(1) x
) t where x>0
is duplicated by
MDEV-24771
Column alias in UNION with GROUP BY query
Closed
{"report":{"fcp":1306.1999998092651,"ttfb":345.69999980926514,"pageVisibility":"visible","entityId":74253,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"f7869394-0cb2-40c6-a779-3d443ad87f52","navigationType":0,"readyForUser":1427.6999998092651,"redirectCount":0,"resourceLoadedEnd":1420,"resourceLoadedStart":352.69999980926514,"resourceTiming":[{"duration":170,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":352.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":352.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":522.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":170.40000009536743,"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":353.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":353.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":523.5,"responseStart":0,"secureConnectionStart":0},{"duration":254.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":353.19999980926514,"connectEnd":353.19999980926514,"connectStart":353.19999980926514,"domainLookupEnd":353.19999980926514,"domainLookupStart":353.19999980926514,"fetchStart":353.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":353.19999980926514,"responseEnd":607.5999999046326,"responseStart":607.5999999046326,"secureConnectionStart":353.19999980926514},{"duration":607.7999997138977,"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":353.40000009536743,"connectEnd":353.40000009536743,"connectStart":353.40000009536743,"domainLookupEnd":353.40000009536743,"domainLookupStart":353.40000009536743,"fetchStart":353.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":353.40000009536743,"responseEnd":961.1999998092651,"responseStart":961.1999998092651,"secureConnectionStart":353.40000009536743},{"duration":611.9000000953674,"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":353.69999980926514,"connectEnd":353.69999980926514,"connectStart":353.69999980926514,"domainLookupEnd":353.69999980926514,"domainLookupStart":353.69999980926514,"fetchStart":353.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":353.69999980926514,"responseEnd":965.5999999046326,"responseStart":965.5,"secureConnectionStart":353.69999980926514},{"duration":612.5,"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":353.80000019073486,"connectEnd":353.80000019073486,"connectStart":353.80000019073486,"domainLookupEnd":353.80000019073486,"domainLookupStart":353.80000019073486,"fetchStart":353.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":353.80000019073486,"responseEnd":966.3000001907349,"responseStart":966.3000001907349,"secureConnectionStart":353.80000019073486},{"duration":612.8000001907349,"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":354,"connectEnd":354,"connectStart":354,"domainLookupEnd":354,"domainLookupStart":354,"fetchStart":354,"redirectEnd":0,"redirectStart":0,"requestStart":354,"responseEnd":966.8000001907349,"responseStart":966.8000001907349,"secureConnectionStart":354},{"duration":613.7000002861023,"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":354.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":354.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":967.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":613.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":354.40000009536743,"connectEnd":354.40000009536743,"connectStart":354.40000009536743,"domainLookupEnd":354.40000009536743,"domainLookupStart":354.40000009536743,"fetchStart":354.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":354.40000009536743,"responseEnd":967.6999998092651,"responseStart":967.6999998092651,"secureConnectionStart":354.40000009536743},{"duration":614.3000001907349,"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":354.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":354.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":968.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":614.6000003814697,"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":354.69999980926514,"connectEnd":354.69999980926514,"connectStart":354.69999980926514,"domainLookupEnd":354.69999980926514,"domainLookupStart":354.69999980926514,"fetchStart":354.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":354.69999980926514,"responseEnd":969.3000001907349,"responseStart":969.3000001907349,"secureConnectionStart":354.69999980926514},{"duration":987.9000000953674,"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":355.59999990463257,"connectEnd":355.59999990463257,"connectStart":355.59999990463257,"domainLookupEnd":355.59999990463257,"domainLookupStart":355.59999990463257,"fetchStart":355.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":355.59999990463257,"responseEnd":1343.5,"responseStart":1343.5,"secureConnectionStart":355.59999990463257},{"duration":989.1000003814697,"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":355.69999980926514,"connectEnd":355.69999980926514,"connectStart":355.69999980926514,"domainLookupEnd":355.69999980926514,"domainLookupStart":355.69999980926514,"fetchStart":355.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":355.69999980926514,"responseEnd":1344.8000001907349,"responseStart":1344.8000001907349,"secureConnectionStart":355.69999980926514},{"duration":208.09999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":765.3000001907349,"connectEnd":765.3000001907349,"connectStart":765.3000001907349,"domainLookupEnd":765.3000001907349,"domainLookupStart":765.3000001907349,"fetchStart":765.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":765.3000001907349,"responseEnd":973.4000000953674,"responseStart":973.4000000953674,"secureConnectionStart":765.3000001907349},{"duration":252.09999990463257,"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":987.5999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":987.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1239.6999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":406.09999990463257,"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":988.5999999046326,"connectEnd":988.5999999046326,"connectStart":988.5999999046326,"domainLookupEnd":988.5999999046326,"domainLookupStart":988.5999999046326,"fetchStart":988.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":988.5999999046326,"responseEnd":1394.6999998092651,"responseStart":1394.5999999046326,"secureConnectionStart":988.5999999046326},{"duration":170.40000009536743,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1295.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1295.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1466.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":430.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":989.0999999046326,"connectEnd":989.0999999046326,"connectStart":989.0999999046326,"domainLookupEnd":989.0999999046326,"domainLookupStart":989.0999999046326,"fetchStart":989.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":989.0999999046326,"responseEnd":1420,"responseStart":1420,"secureConnectionStart":989.0999999046326},{"duration":158.19999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1314.9000000953674,"connectEnd":1314.9000000953674,"connectStart":1314.9000000953674,"domainLookupEnd":1314.9000000953674,"domainLookupStart":1314.9000000953674,"fetchStart":1314.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1314.9000000953674,"responseEnd":1473.0999999046326,"responseStart":1473.0999999046326,"secureConnectionStart":1314.9000000953674}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":179,"responseStart":345,"responseEnd":350,"domLoading":350,"domInteractive":1509,"domContentLoadedEventStart":1509,"domContentLoadedEventEnd":1552,"domComplete":1726,"loadEventStart":1726,"loadEventEnd":1727,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1471.1999998092651},{"name":"bigPipe.sidebar-id.end","time":1472.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1472.1999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":1473.5},{"name":"activityTabFullyLoaded","time":1573.0999999046326}],"measures":[],"correlationId":"f0f8227eb3c218","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":103,"dbReadsTimeInMs":13,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thanks! Repeatable on 10.2-10.4