Type:
Bug
Priority:
Critical
Resolution:
Fixed
Affects Version/s:
None
Fix Version/s:
None
Component/s:
None
A query with IN subquery that can be converted to a semi-join may return a wrong result in maridb-5.3 if the where clause of the subquery contains OR condition.
The following test case provides such a query.
create table t1 (a int, b int);
insert into t1 values (7,5), (3,3), (5,4), (9,3);
create table t2 (a int, b int, index i_a(a));
insert into t2 values
(4,2), (7,9), (7,4), (3,1), (5,3), (3,1), (9,4), (8,1);
set optimizer_switch='semijoin=on,materialization=on';
select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
The query in from the test case returns a wrong result if the optimizer switch flags 'semijoin' and 'materialization' are set to 'on', a it returns the correct answer if these flags are set to 'off'.
MariaDB [test] > set optimizer_switch='semijoin=on,materialization=on';
Query OK, 0 rows affected (0.00 sec)
MariaDB [test] > select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
----- -----+
----- -----+
----- -----+
4 rows in set (0.00 sec)
MariaDB [test] > set optimizer_switch='semijoin=off,materialization=off';
Query OK, 0 rows affected (0.00 sec)
MariaDB [test] > select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
----- -----+
----- -----+
----- -----+
2 rows in set (0.00 sec)
The warning returned by EXPLAIN EXTENDED executed for the query with
optimizer_switch set to 'semijoin=on,materialization=on'
shows that it happens because in this case the optimizer generates an invalid execution plan:
MariaDB [test] > set optimizer_switch='semijoin=on,materialization=on';
Query OK, 0 rows affected (0.00 sec)
MariaDB [test] > explain extended
-> select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1);
--- -----------------------------------------------------------------------------------
id
select_type
table
type
possible_keys
key
key_len
ref
rows
filtered
Extra
--- -----------------------------------------------------------------------------------
1
PRIMARY
t1
ALL
NULL
NULL
NULL
NULL
4
100.00
1
PRIMARY
<subquery2>
eq_ref
distinct_key
distinct_key
5
func
1
100.00
2
MATERIALIZED
t2
ALL
i_a
NULL
NULL
NULL
8
100.00
--- -----------------------------------------------------------------------------------
3 rows in set, 1 warning (0.00 sec)
MariaDB [test] > show warnings;
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------
Note
1003
select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join (`test`.`t2`) where (((`test`.`t1`.`a` = 7) or (`test`.`t2`.`b` <= 1)))
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------
1 row in set (0.00 sec)
{"report":{"fcp":773.6999999284744,"ttfb":166.19999992847443,"pageVisibility":"visible","entityId":21179,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"f4646171-f357-4807-ab92-ab0cb49dd858","navigationType":0,"readyForUser":827,"redirectCount":0,"resourceLoadedEnd":1035.8999999761581,"resourceLoadedStart":175.19999992847443,"resourceTiming":[{"duration":108.70000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":175.19999992847443,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":175.19999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":283.89999997615814,"responseStart":0,"secureConnectionStart":0},{"duration":108.39999997615814,"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":175.60000002384186,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":175.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":284,"responseStart":0,"secureConnectionStart":0},{"duration":119,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":175.69999992847443,"connectEnd":175.69999992847443,"connectStart":175.69999992847443,"domainLookupEnd":175.69999992847443,"domainLookupStart":175.69999992847443,"fetchStart":175.69999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":175.69999992847443,"responseEnd":294.6999999284744,"responseStart":294.6999999284744,"secureConnectionStart":175.69999992847443},{"duration":187.5,"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":176.10000002384186,"connectEnd":176.10000002384186,"connectStart":176.10000002384186,"domainLookupEnd":176.10000002384186,"domainLookupStart":176.10000002384186,"fetchStart":176.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":176.10000002384186,"responseEnd":363.60000002384186,"responseStart":363.60000002384186,"secureConnectionStart":176.10000002384186},{"duration":191,"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":176.19999992847443,"connectEnd":176.19999992847443,"connectStart":176.19999992847443,"domainLookupEnd":176.19999992847443,"domainLookupStart":176.19999992847443,"fetchStart":176.19999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":176.19999992847443,"responseEnd":367.1999999284744,"responseStart":367.1999999284744,"secureConnectionStart":176.19999992847443},{"duration":191.89999997615814,"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":176.29999995231628,"connectEnd":176.29999995231628,"connectStart":176.29999995231628,"domainLookupEnd":176.29999995231628,"domainLookupStart":176.29999995231628,"fetchStart":176.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":176.29999995231628,"responseEnd":368.1999999284744,"responseStart":368.1999999284744,"secureConnectionStart":176.29999995231628},{"duration":192.39999997615814,"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":176.39999997615814,"connectEnd":176.39999997615814,"connectStart":176.39999997615814,"domainLookupEnd":176.39999997615814,"domainLookupStart":176.39999997615814,"fetchStart":176.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":176.39999997615814,"responseEnd":368.7999999523163,"responseStart":368.7999999523163,"secureConnectionStart":176.39999997615814},{"duration":193.39999997615814,"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":176.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":176.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":369.89999997615814,"responseStart":0,"secureConnectionStart":0},{"duration":193.60000002384186,"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":176.69999992847443,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":176.69999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":370.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":193.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":176.69999992847443,"connectEnd":176.69999992847443,"connectStart":176.69999992847443,"domainLookupEnd":176.69999992847443,"domainLookupStart":176.69999992847443,"fetchStart":176.69999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":176.69999992847443,"responseEnd":369.7999999523163,"responseStart":369.7999999523163,"secureConnectionStart":176.69999992847443},{"duration":193.39999997615814,"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":176.89999997615814,"connectEnd":176.89999997615814,"connectStart":176.89999997615814,"domainLookupEnd":176.89999997615814,"domainLookupStart":176.89999997615814,"fetchStart":176.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":176.89999997615814,"responseEnd":370.2999999523163,"responseStart":370.2999999523163,"secureConnectionStart":176.89999997615814},{"duration":392.10000002384186,"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":184.79999995231628,"connectEnd":184.79999995231628,"connectStart":184.79999995231628,"domainLookupEnd":184.79999995231628,"domainLookupStart":184.79999995231628,"fetchStart":184.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":184.79999995231628,"responseEnd":576.8999999761581,"responseStart":576.8999999761581,"secureConnectionStart":184.79999995231628},{"duration":849.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":186.10000002384186,"connectEnd":186.10000002384186,"connectStart":186.10000002384186,"domainLookupEnd":186.10000002384186,"domainLookupStart":186.10000002384186,"fetchStart":186.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":186.10000002384186,"responseEnd":1035.8999999761581,"responseStart":1035.8999999761581,"secureConnectionStart":186.10000002384186},{"duration":269.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":509.39999997615814,"connectEnd":509.39999997615814,"connectStart":509.39999997615814,"domainLookupEnd":509.39999997615814,"domainLookupStart":509.39999997615814,"fetchStart":509.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":509.39999997615814,"responseEnd":778.8999999761581,"responseStart":778.7999999523163,"secureConnectionStart":509.39999997615814}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":36,"responseStart":167,"responseEnd":186,"domLoading":170,"domInteractive":1053,"domContentLoadedEventStart":1053,"domContentLoadedEventEnd":1089,"domComplete":1970,"loadEventStart":1971,"loadEventEnd":1972,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1040.5},{"name":"bigPipe.sidebar-id.end","time":1041.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":1041.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1043.7999999523163},{"name":"activityTabFullyLoaded","time":1096.6999999284744}],"measures":[],"correlationId":"e5d45d7d09ebb1","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":72,"dbReadsTimeInMs":6,"dbConnsTimeInMs":11,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}