Type:
Bug
Priority:
Major
Resolution:
Duplicate
Affects Version/s:
None
Component/s:
None
The following query
SELECT STRAIGHT_JOIN * FROM t1 AS alias1, t1 AS alias2
WHERE EXISTS ( SELECT 1 FROM t1 WHERE b < alias2.b AND a = alias1.a )
on the test data produces 4 rows if it's run with exists_to_in=on, and 1 row otherwise. 1 row is the correct result.
bzr version-info
revision-id: sanja@askmonty.org-20120718105902-imt07qp0v913sqa4
date: 2012-07-18 13:59:02 +0300
build-date: 2012-07-19 21:33:12 +0400
revno: 3466
Reproducible with MyISAM, Aria, InnoDB.
Minimal optimizer_switch:
exists_to_in=on,in_to_exists=on
Full optimizer_switch (default + exists_to_in=on):
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=off,exists_to_in=on
EXPLAIN with the minimal optimizer_switch (exists_to_in=on,in_to_exists=on, everything else OFF):
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 100.00 Using where
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.alias2.b' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.alias1.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select straight_join `test`.`alias1`.`a` AS `a`,`test`.`alias1`.`b` AS `b`,`test`.`alias2`.`a` AS `a`,`test`.`alias2`.`b` AS `b` from `test`.`t1` `alias1` join `test`.`t1` `alias2` where <in_optimizer>(`test`.`alias1`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` where ((`test`.`t1`.`b` < `test`.`alias2`.`b`) and (<cache>(`test`.`alias1`.`a`) = `test`.`t1`.`a`))))
EXPLAIN with the default optimizer_switch + exists_to_in=on:
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY alias1 ALL NULL NULL NULL NULL 2 100.00 Using where
1 PRIMARY alias2 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join)
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.alias2.b' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.alias1.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select straight_join `test`.`alias1`.`a` AS `a`,`test`.`alias1`.`b` AS `b`,`test`.`alias2`.`a` AS `a`,`test`.`alias2`.`b` AS `b` from `test`.`t1` `alias1` join `test`.`t1` `alias2` where <expr_cache><`test`.`alias1`.`a`,`test`.`alias2`.`b`>(<in_optimizer>(`test`.`alias1`.`a`,<exists>(select `test`.`t1`.`a` from `test`.`t1` where ((`test`.`t1`.`b` < `test`.`alias2`.`b`) and (<cache>(`test`.`alias1`.`a`) = `test`.`t1`.`a`)))))
Test case:
SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
CREATE TABLE t1 (a INT, b VARCHAR(1) NOT NULL);
INSERT INTO t1 VALUES (1,'s'),(2,'e');
SELECT STRAIGHT_JOIN * FROM t1 AS alias1, t1 AS alias2
WHERE EXISTS ( SELECT 1 FROM t1 WHERE b < alias2.b AND a = alias1.a );
Expected result:
Actual result:
a b a b
1 s 1 s
2 e 1 s
1 s 2 e
2 e 2 e
Please note that removing 'NOT NULL' option from the column definition makes the same query return an empty result, which is also incorrect.
relates to
MDEV-38
NOT EXISTS to IN (part of exists2in transformation for 10.0)
Closed
{"report":{"fcp":849.5999999046326,"ttfb":257.2999999523163,"pageVisibility":"visible","entityId":12609,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"4c081a63-404d-49eb-96a6-6a5e24a4b737","navigationType":0,"readyForUser":912.5,"redirectCount":0,"resourceLoadedEnd":800.3999999761581,"resourceLoadedStart":275.59999990463257,"resourceTiming":[{"duration":113.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":275.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":275.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":389.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":112.29999995231628,"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":276.89999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":276.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":389.1999999284744,"responseStart":0,"secureConnectionStart":0},{"duration":121.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":277,"connectEnd":277,"connectStart":277,"domainLookupEnd":277,"domainLookupStart":277,"fetchStart":277,"redirectEnd":0,"redirectStart":0,"requestStart":277,"responseEnd":398.59999990463257,"responseStart":398.59999990463257,"secureConnectionStart":277},{"duration":191.19999992847443,"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":277.5,"connectEnd":277.5,"connectStart":277.5,"domainLookupEnd":277.5,"domainLookupStart":277.5,"fetchStart":277.5,"redirectEnd":0,"redirectStart":0,"requestStart":277.5,"responseEnd":468.6999999284744,"responseStart":468.6999999284744,"secureConnectionStart":277.5},{"duration":194.80000007152557,"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":277.6999999284744,"connectEnd":277.6999999284744,"connectStart":277.6999999284744,"domainLookupEnd":277.6999999284744,"domainLookupStart":277.6999999284744,"fetchStart":277.6999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":277.6999999284744,"responseEnd":472.5,"responseStart":472.5,"secureConnectionStart":277.6999999284744},{"duration":195.30000007152557,"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":277.6999999284744,"connectEnd":277.6999999284744,"connectStart":277.6999999284744,"domainLookupEnd":277.6999999284744,"domainLookupStart":277.6999999284744,"fetchStart":277.6999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":277.6999999284744,"responseEnd":473,"responseStart":473,"secureConnectionStart":277.6999999284744},{"duration":195.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":277.7999999523163,"connectEnd":277.7999999523163,"connectStart":277.7999999523163,"domainLookupEnd":277.7999999523163,"domainLookupStart":277.7999999523163,"fetchStart":277.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":277.7999999523163,"responseEnd":473.2999999523163,"responseStart":473.2999999523163,"secureConnectionStart":277.7999999523163},{"duration":195.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":277.89999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":277.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":473.6999999284744,"responseStart":0,"secureConnectionStart":0},{"duration":195.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":278,"connectEnd":278,"connectStart":278,"domainLookupEnd":278,"domainLookupStart":278,"fetchStart":278,"redirectEnd":0,"redirectStart":0,"requestStart":278,"responseEnd":473.7999999523163,"responseStart":473.7999999523163,"secureConnectionStart":278},{"duration":196,"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":278.1999999284744,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":278.1999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":474.1999999284744,"responseStart":0,"secureConnectionStart":0},{"duration":196.10000002384186,"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":278.2999999523163,"connectEnd":278.2999999523163,"connectStart":278.2999999523163,"domainLookupEnd":278.2999999523163,"domainLookupStart":278.2999999523163,"fetchStart":278.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":278.2999999523163,"responseEnd":474.39999997615814,"responseStart":474.39999997615814,"secureConnectionStart":278.2999999523163},{"duration":344.7999999523163,"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":332.5,"connectEnd":332.5,"connectStart":332.5,"domainLookupEnd":332.5,"domainLookupStart":332.5,"fetchStart":332.5,"redirectEnd":0,"redirectStart":0,"requestStart":332.5,"responseEnd":677.2999999523163,"responseStart":677.2999999523163,"secureConnectionStart":332.5},{"duration":446.5,"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":353.89999997615814,"connectEnd":353.89999997615814,"connectStart":353.89999997615814,"domainLookupEnd":353.89999997615814,"domainLookupStart":353.89999997615814,"fetchStart":353.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":353.89999997615814,"responseEnd":800.3999999761581,"responseStart":800.3999999761581,"secureConnectionStart":353.89999997615814},{"duration":131.89999997615814,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":609.7999999523163,"connectEnd":609.7999999523163,"connectStart":609.7999999523163,"domainLookupEnd":609.7999999523163,"domainLookupStart":609.7999999523163,"fetchStart":609.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":609.7999999523163,"responseEnd":741.6999999284744,"responseStart":741.6999999284744,"secureConnectionStart":609.7999999523163}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":78,"responseStart":257,"responseEnd":354,"domLoading":260,"domInteractive":967,"domContentLoadedEventStart":967,"domContentLoadedEventEnd":1003,"domComplete":1819,"loadEventStart":1819,"loadEventEnd":1820,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":948.3999999761581},{"name":"bigPipe.sidebar-id.end","time":949.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":949.1999999284744},{"name":"bigPipe.activity-panel-pipe-id.end","time":951.5},{"name":"activityTabFullyLoaded","time":1014.7999999523163}],"measures":[],"correlationId":"d38ff493ee4cbf","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":99,"dbReadsTimeInMs":9,"dbConnsTimeInMs":16,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}