Look at testcase for MDEV-20557 in subselect_exists2in.result:
create table t1 (id int, id2 int);
|
create table t2 (id int, id2 int, a int);
|
create table t3 (id int);
|
create table t4 (id int);
|
select (select 1 from t1 where (exists
|
(select 1 from t2
|
where t2.a = (select t4.id from t4 where t4.id = t3.id) and t2.id2 = t1.id2))) dt
|
from t3;
|
ERROR 42000: This version of MariaDB doesn't yet support 'SUBQUERY in ROW in left expression of IN/ALL/ANY'
|
It is wrong that this query produces an error.
Running the select with optimizer_switch='exists_to_in=off' produces no error.
Also, swapping the order of conjuncts in the subquery's WHERE clause causes no error to be produced:
MariaDB [test]> select (select 1 from t1 where (exists
|
-> (select 1 from t2
|
-> where t2.a = (select t4.id from t4 where t4.id = t3.id) and t2.id2 = t1.id2))) dt
|
-> from t3;
|
ERROR 1235 (42000): This version of MariaDB doesn't yet support 'SUBQUERY in ROW in left expression of IN/ALL/ANY'
|
|
MariaDB [test]>
|
MariaDB [test]> select (select 1 from t1 where (exists
|
-> (select 1 from t2
|
-> where t2.id2 = t1.id2 and t2.a = (select t4.id from t4 where t4.id = t3.id)))) dt
|
-> from t3;
|
Empty set (0.001 sec)
|
The testcase is from MDEV-20557. But we've only pushed a testcase for that bug.
The patch that has introduced the problem is the fix for MDEV-23221.
That patch has added this logic into find_inner_outer_equalities():
+ if there is just one outer_expr=inner_expr pair, then outer_expr can have a
|
+ subselect in it. If there are many such pairs, then none of outer_expr can
|
+ have a subselect in it. If we allow this, the query will fail with an error:
|
+
|
+ This version of MariaDB doesn't yet support 'SUBQUERY in ROW in left
|
+ expression of IN/ALL/ANY'
|
The problem is that it doesn't implement it correctly. If the first equality has a subselect and the second one doesn't, the code in find_inner_outer_equalities() still allows this.
{"report":{"fcp":1100.0999999046326,"ttfb":388.7000002861023,"pageVisibility":"visible","entityId":126721,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"63f6260d-5f07-4663-969d-5e23e0753016","navigationType":0,"readyForUser":1185.5999999046326,"redirectCount":0,"resourceLoadedEnd":1223.9000000953674,"resourceLoadedStart":394.7000002861023,"resourceTiming":[{"duration":163.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":394.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":394.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":557.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":164.59999990463257,"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":394.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":394.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":559.5,"responseStart":0,"secureConnectionStart":0},{"duration":217.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":395.2000002861023,"connectEnd":395.2000002861023,"connectStart":395.2000002861023,"domainLookupEnd":395.2000002861023,"domainLookupStart":395.2000002861023,"fetchStart":395.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":395.2000002861023,"responseEnd":612.8000001907349,"responseStart":612.8000001907349,"secureConnectionStart":395.2000002861023},{"duration":270.5,"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":395.30000019073486,"connectEnd":395.30000019073486,"connectStart":395.30000019073486,"domainLookupEnd":395.30000019073486,"domainLookupStart":395.30000019073486,"fetchStart":395.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":395.30000019073486,"responseEnd":665.8000001907349,"responseStart":665.8000001907349,"secureConnectionStart":395.30000019073486},{"duration":274.2000002861023,"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":395.5,"connectEnd":395.5,"connectStart":395.5,"domainLookupEnd":395.5,"domainLookupStart":395.5,"fetchStart":395.5,"redirectEnd":0,"redirectStart":0,"requestStart":395.5,"responseEnd":669.7000002861023,"responseStart":669.7000002861023,"secureConnectionStart":395.5},{"duration":274.40000009536743,"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":395.80000019073486,"connectEnd":395.80000019073486,"connectStart":395.80000019073486,"domainLookupEnd":395.80000019073486,"domainLookupStart":395.80000019073486,"fetchStart":395.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":395.80000019073486,"responseEnd":670.2000002861023,"responseStart":670.2000002861023,"secureConnectionStart":395.80000019073486},{"duration":274.59999990463257,"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":395.90000009536743,"connectEnd":395.90000009536743,"connectStart":395.90000009536743,"domainLookupEnd":395.90000009536743,"domainLookupStart":395.90000009536743,"fetchStart":395.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":395.90000009536743,"responseEnd":670.5,"responseStart":670.5,"secureConnectionStart":395.90000009536743},{"duration":365.3999996185303,"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":396.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":396.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":761.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":274.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":396.30000019073486,"connectEnd":396.30000019073486,"connectStart":396.30000019073486,"domainLookupEnd":396.30000019073486,"domainLookupStart":396.30000019073486,"fetchStart":396.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":396.30000019073486,"responseEnd":671,"responseStart":671,"secureConnectionStart":396.30000019073486},{"duration":365.30000019073486,"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":396.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":396.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":761.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":274.8999996185303,"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":396.7000002861023,"connectEnd":396.7000002861023,"connectStart":396.7000002861023,"domainLookupEnd":396.7000002861023,"domainLookupStart":396.7000002861023,"fetchStart":396.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":396.7000002861023,"responseEnd":671.5999999046326,"responseStart":671.5999999046326,"secureConnectionStart":396.7000002861023},{"duration":639.7000002861023,"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":397.5,"connectEnd":397.5,"connectStart":397.5,"domainLookupEnd":397.5,"domainLookupStart":397.5,"fetchStart":397.5,"redirectEnd":0,"redirectStart":0,"requestStart":397.5,"responseEnd":1037.2000002861023,"responseStart":1037.0999999046326,"secureConnectionStart":397.5},{"duration":818.5,"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":397.5,"connectEnd":397.5,"connectStart":397.5,"domainLookupEnd":397.5,"domainLookupStart":397.5,"fetchStart":397.5,"redirectEnd":0,"redirectStart":0,"requestStart":397.5,"responseEnd":1216,"responseStart":1216,"secureConnectionStart":397.5},{"duration":267,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":773.4000000953674,"connectEnd":773.4000000953674,"connectStart":773.4000000953674,"domainLookupEnd":773.4000000953674,"domainLookupStart":773.4000000953674,"fetchStart":773.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":773.4000000953674,"responseEnd":1040.4000000953674,"responseStart":1040.4000000953674,"secureConnectionStart":773.4000000953674},{"duration":169.90000009536743,"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":1050.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1050.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1220.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":166.90000009536743,"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":1051.4000000953674,"connectEnd":1051.4000000953674,"connectStart":1051.4000000953674,"domainLookupEnd":1051.4000000953674,"domainLookupStart":1051.4000000953674,"fetchStart":1051.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1051.4000000953674,"responseEnd":1218.3000001907349,"responseStart":1218.3000001907349,"secureConnectionStart":1051.4000000953674},{"duration":172.09999990463257,"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":1051.8000001907349,"connectEnd":1051.8000001907349,"connectStart":1051.8000001907349,"domainLookupEnd":1051.8000001907349,"domainLookupStart":1051.8000001907349,"fetchStart":1051.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1051.8000001907349,"responseEnd":1223.9000000953674,"responseStart":1223.9000000953674,"secureConnectionStart":1051.8000001907349}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":231,"responseStart":389,"responseEnd":392,"domLoading":392,"domInteractive":1284,"domContentLoadedEventStart":1284,"domContentLoadedEventEnd":1327,"domComplete":1626,"loadEventStart":1626,"loadEventEnd":1626,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1250.3000001907349},{"name":"bigPipe.sidebar-id.end","time":1252.2000002861023},{"name":"bigPipe.activity-panel-pipe-id.start","time":1252.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":1253.7000002861023},{"name":"activityTabFullyLoaded","time":1341.5999999046326}],"measures":[],"correlationId":"28734d7217f32","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":98,"dbReadsTimeInMs":12,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Suppose we have
EXISTS (
SELECT 1
FROM t1
WHERE
t1.col1 = outer_tbl.col1 AND --(1)
t1.col2 = (SELECT ... FROM t2 WHERE ... outer_tbl.col2...) AND -- (2)
t1.col3 = (SELECT ... FROM t3 WHERE ... outer_tbl.col3...) AND -- (3)
t1.col4 = outer_tbl.col4 --(4)
In this case, EXISTS-to-IN can pick either:
.
Its hard to make a cost-based choice here. and should we bother?
Will raise this on the optimizer call.