Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
10.5
If a query contains a degenerated subquery with window function then the query may return a wrong result.
This can be seen for the following examples:
CREATE TABLE t1 (a int DEFAULT 10);
INSERT INTO t1 VALUES (7), (2), (3);
SELECT * FROM t1 WHERE ( SELECT AVG (3)) > 2;
SELECT * FROM t1 WHERE ( SELECT AVG (3) OVER ()) > 2;
INSERT INTO t1 VALUES (( SELECT avg (4) OVER ()));
SELECT * FROM t1;
For the above test case we have
MariaDB [test]> CREATE TABLE t1 (a int DEFAULT 10);
Query OK, 0 rows affected (0.017 sec)
MariaDB [test]> INSERT INTO t1 VALUES (7), (2), (3);
Query OK, 3 rows affected (0.002 sec)
Records: 3 Duplicates: 0 Warnings: 0
MariaDB [test]> SELECT * FROM t1 WHERE (SELECT AVG(3)) > 2;
+------+
| a |
+------+
| 7 |
| 2 |
| 3 |
+------+
3 rows in set (0.003 sec)
MariaDB [test]> SELECT * FROM t1 WHERE (SELECT AVG(3) OVER ()) > 2;
Empty set (0.000 sec)
MariaDB [test]> INSERT INTO t1 VALUES((SELECT avg(4) OVER ()));
Query OK, 1 row affected (0.002 sec)
MariaDB [test]> SELECT * FROM t1;
+------+
| a |
+------+
| 7 |
| 2 |
| 3 |
| NULL |
+------+
4 rows in set (0.001 sec)
For the second select the expected result is the same as for the first select. For the last select the expected result has to contain 4 instead of NULL.
{"report":{"fcp":740.5,"ttfb":178.09999990463257,"pageVisibility":"visible","entityId":132417,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"108a8808-7a75-451b-8741-a406c8f98485","navigationType":0,"readyForUser":816.8999998569489,"redirectCount":0,"resourceLoadedEnd":481.89999985694885,"resourceLoadedStart":187,"resourceTiming":[{"duration":17.299999952316284,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":187,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":187,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":204.29999995231628,"responseStart":0,"secureConnectionStart":0},{"duration":17.5,"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":187.29999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":187.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":204.79999995231628,"responseStart":0,"secureConnectionStart":0},{"duration":172.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":187.29999995231628,"connectEnd":187.29999995231628,"connectStart":187.29999995231628,"domainLookupEnd":187.29999995231628,"domainLookupStart":187.29999995231628,"fetchStart":187.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":207.5,"responseEnd":359.59999990463257,"responseStart":233.69999980926514,"secureConnectionStart":187.29999995231628},{"duration":294.39999985694885,"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":187.5,"connectEnd":187.5,"connectStart":187.5,"domainLookupEnd":187.5,"domainLookupStart":187.5,"fetchStart":187.5,"redirectEnd":0,"redirectStart":0,"requestStart":208.59999990463257,"responseEnd":481.89999985694885,"responseStart":245.09999990463257,"secureConnectionStart":187.5},{"duration":48.200000047683716,"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":187.59999990463257,"connectEnd":187.59999990463257,"connectStart":187.59999990463257,"domainLookupEnd":187.59999990463257,"domainLookupStart":187.59999990463257,"fetchStart":187.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":208.79999995231628,"responseEnd":235.79999995231628,"responseStart":234.29999995231628,"secureConnectionStart":187.59999990463257},{"duration":49.40000009536743,"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":187.69999980926514,"connectEnd":187.69999980926514,"connectStart":187.69999980926514,"domainLookupEnd":187.69999980926514,"domainLookupStart":187.69999980926514,"fetchStart":187.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":210.19999980926514,"responseEnd":237.09999990463257,"responseStart":236.09999990463257,"secureConnectionStart":187.69999980926514},{"duration":52.59999990463257,"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":187.79999995231628,"connectEnd":187.79999995231628,"connectStart":187.79999995231628,"domainLookupEnd":187.79999995231628,"domainLookupStart":187.79999995231628,"fetchStart":187.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":213.5,"responseEnd":240.39999985694885,"responseStart":238.59999990463257,"secureConnectionStart":187.79999995231628},{"duration":21.5,"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":187.89999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":187.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":209.39999985694885,"responseStart":0,"secureConnectionStart":0},{"duration":120.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":188,"connectEnd":188,"connectStart":188,"domainLookupEnd":188,"domainLookupStart":188,"fetchStart":188,"redirectEnd":0,"redirectStart":0,"requestStart":215.29999995231628,"responseEnd":308.69999980926514,"responseStart":307.09999990463257,"secureConnectionStart":188},{"duration":22.90000009536743,"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":188.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":188.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":211,"responseStart":0,"secureConnectionStart":0},{"duration":52.40000009536743,"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":188.19999980926514,"connectEnd":188.19999980926514,"connectStart":188.19999980926514,"domainLookupEnd":188.19999980926514,"domainLookupStart":188.19999980926514,"fetchStart":188.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":216.59999990463257,"responseEnd":240.59999990463257,"responseStart":239.09999990463257,"secureConnectionStart":188.19999980926514},{"duration":233.79999995231628,"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":188.79999995231628,"connectEnd":188.79999995231628,"connectStart":188.79999995231628,"domainLookupEnd":188.79999995231628,"domainLookupStart":188.79999995231628,"fetchStart":188.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":226.19999980926514,"responseEnd":422.59999990463257,"responseStart":420.89999985694885,"secureConnectionStart":188.79999995231628},{"duration":288.7999999523163,"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":190.89999985694885,"connectEnd":190.89999985694885,"connectStart":190.89999985694885,"domainLookupEnd":190.89999985694885,"domainLookupStart":190.89999985694885,"fetchStart":190.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":235.29999995231628,"responseEnd":479.69999980926514,"responseStart":475.69999980926514,"secureConnectionStart":190.89999985694885},{"duration":160.09999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":504,"connectEnd":504,"connectStart":504,"domainLookupEnd":504,"domainLookupStart":504,"fetchStart":504,"redirectEnd":0,"redirectStart":0,"requestStart":635.6999998092651,"responseEnd":664.0999999046326,"responseStart":663.2999999523163,"secureConnectionStart":504},{"duration":139.29999995231628,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":734.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":734.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":873.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":167,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":740.6999998092651,"connectEnd":740.6999998092651,"connectStart":740.6999998092651,"domainLookupEnd":740.6999998092651,"domainLookupStart":740.6999998092651,"fetchStart":740.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":874.5999999046326,"responseEnd":907.6999998092651,"responseStart":905.7999999523163,"secureConnectionStart":740.6999998092651}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":37,"responseStart":178,"responseEnd":193,"domLoading":182,"domInteractive":917,"domContentLoadedEventStart":917,"domContentLoadedEventEnd":962,"domComplete":1324,"loadEventStart":1324,"loadEventEnd":1325,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":892.6999998092651},{"name":"bigPipe.sidebar-id.end","time":893.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":893.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":894.8999998569489},{"name":"activityTabFullyLoaded","time":979.5999999046326}],"measures":[],"correlationId":"798cb8cd6fa02f","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":68,"dbReadsTimeInMs":11,"dbConnsTimeInMs":17,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
The transformation of a such a subquery
(SELECT <expr>)
into
<expr>
is not valid if <expr> contains set_functions or window function.
The transformation was not applied when <expr> contained window function, but erroneously was applied if <expr> contained only window functions.