Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
None
Component/s:
None
The following query
SELECT * FROM t1 AS alias1, t2 AS alias2
WHERE EXISTS (
SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
) OR a = 5
on the test data returns an empty result set 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 19:49:58 +0400
revno: 3466
Reproducible with any of MyISAM, Aria, InnoDB.
Minimal optimizer_switch:
exists_to_in=on,in_to_exists=on
Full optimizer_switch (default + in_to_exists=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 switch (exists_to_in=on,in_to_exists=on, everything else is 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 t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.alias1.a' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.alias2.b' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`alias1`.`a` AS `a`,`test`.`alias2`.`b` AS `b` from `test`.`t1` `alias1` join `test`.`t2` `alias2` where (<in_optimizer>(`test`.`alias1`.`a`,<exists>(select `test`.`t2`.`b` from `test`.`t2` where ((`test`.`t2`.`b` > `test`.`alias2`.`b`) and (<cache>(`test`.`alias1`.`a`) = `test`.`t2`.`b`)))) or (`test`.`alias1`.`a` = 5))
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 t2 ALL NULL NULL NULL NULL 2 100.00 Using where
Warnings:
Note 1276 Field or reference 'test.alias1.a' of SELECT #2 was resolved in SELECT #1
Note 1276 Field or reference 'test.alias2.b' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`alias1`.`a` AS `a`,`test`.`alias2`.`b` AS `b` from `test`.`t1` `alias1` join `test`.`t2` `alias2` where (<expr_cache><`test`.`alias1`.`a`,`test`.`alias2`.`b`>(<in_optimizer>(`test`.`alias1`.`a`,<exists>(select `test`.`t2`.`b` from `test`.`t2` where ((`test`.`t2`.`b` > `test`.`alias2`.`b`) and (<cache>(`test`.`alias1`.`a`) = `test`.`t2`.`b`))))) or (`test`.`alias1`.`a` = 5))
Test case:
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (2),(3);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (1),(3);
SET optimizer_switch = 'exists_to_in=on,in_to_exists=on';
SELECT * FROM t1 AS alias1, t2 AS alias2
WHERE EXISTS (
SELECT 1 FROM t2 WHERE b = alias1.a AND b > alias2.b
) OR a = 5;
Expected result:
Actual result:
relates to
MDEV-38
NOT EXISTS to IN (part of exists2in transformation for 10.0)
Closed
{"report":{"fcp":1310.6999998092651,"ttfb":372.80000019073486,"pageVisibility":"visible","entityId":12608,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"2db69179-b6b3-48c2-ac29-e17757d60533","navigationType":0,"readyForUser":1391.1999998092651,"redirectCount":0,"resourceLoadedEnd":1905.3000001907349,"resourceLoadedStart":378.09999990463257,"resourceTiming":[{"duration":401.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":378.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":378.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":779.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":401.90000009536743,"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":378.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":378.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":780.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":433.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":378.59999990463257,"connectEnd":378.59999990463257,"connectStart":378.59999990463257,"domainLookupEnd":378.59999990463257,"domainLookupStart":378.59999990463257,"fetchStart":378.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":378.59999990463257,"responseEnd":811.8000001907349,"responseStart":811.8000001907349,"secureConnectionStart":378.59999990463257},{"duration":499.59999990463257,"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":378.90000009536743,"connectEnd":378.90000009536743,"connectStart":378.90000009536743,"domainLookupEnd":378.90000009536743,"domainLookupStart":378.90000009536743,"fetchStart":378.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":378.90000009536743,"responseEnd":878.5,"responseStart":878.5,"secureConnectionStart":378.90000009536743},{"duration":504,"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":379,"connectEnd":379,"connectStart":379,"domainLookupEnd":379,"domainLookupStart":379,"fetchStart":379,"redirectEnd":0,"redirectStart":0,"requestStart":379,"responseEnd":883,"responseStart":883,"secureConnectionStart":379},{"duration":504.30000019073486,"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":379.09999990463257,"connectEnd":379.09999990463257,"connectStart":379.09999990463257,"domainLookupEnd":379.09999990463257,"domainLookupStart":379.09999990463257,"fetchStart":379.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":379.09999990463257,"responseEnd":883.4000000953674,"responseStart":883.4000000953674,"secureConnectionStart":379.09999990463257},{"duration":504.30000019073486,"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":379.5,"connectEnd":379.5,"connectStart":379.5,"domainLookupEnd":379.5,"domainLookupStart":379.5,"fetchStart":379.5,"redirectEnd":0,"redirectStart":0,"requestStart":379.5,"responseEnd":883.8000001907349,"responseStart":883.8000001907349,"secureConnectionStart":379.5},{"duration":584.8000001907349,"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":379.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":379.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":964.5,"responseStart":0,"secureConnectionStart":0},{"duration":504.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":379.80000019073486,"connectEnd":379.80000019073486,"connectStart":379.80000019073486,"domainLookupEnd":379.80000019073486,"domainLookupStart":379.80000019073486,"fetchStart":379.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":379.80000019073486,"responseEnd":884.4000000953674,"responseStart":884.4000000953674,"secureConnectionStart":379.80000019073486},{"duration":584.5999999046326,"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":380,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":380,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":964.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":504.90000009536743,"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":380.09999990463257,"connectEnd":380.09999990463257,"connectStart":380.09999990463257,"domainLookupEnd":380.09999990463257,"domainLookupStart":380.09999990463257,"fetchStart":380.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":380.09999990463257,"responseEnd":885,"responseStart":885,"secureConnectionStart":380.09999990463257},{"duration":759.5999999046326,"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":386,"connectEnd":386,"connectStart":386,"domainLookupEnd":386,"domainLookupStart":386,"fetchStart":386,"redirectEnd":0,"redirectStart":0,"requestStart":386,"responseEnd":1145.5999999046326,"responseStart":1145.5999999046326,"secureConnectionStart":386},{"duration":1519.3000001907349,"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":386,"connectEnd":386,"connectStart":386,"domainLookupEnd":386,"domainLookupStart":386,"fetchStart":386,"redirectEnd":0,"redirectStart":0,"requestStart":386,"responseEnd":1905.3000001907349,"responseStart":1905.3000001907349,"secureConnectionStart":386},{"duration":168.40000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":977.5999999046326,"connectEnd":977.5999999046326,"connectStart":977.5999999046326,"domainLookupEnd":977.5999999046326,"domainLookupStart":977.5999999046326,"fetchStart":977.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":977.5999999046326,"responseEnd":1146,"responseStart":1146,"secureConnectionStart":977.5999999046326},{"duration":733.3000001907349,"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":1242.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1242.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1976,"responseStart":0,"secureConnectionStart":0},{"duration":709.9000000953674,"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":1244.5,"connectEnd":1244.5,"connectStart":1244.5,"domainLookupEnd":1244.5,"domainLookupStart":1244.5,"fetchStart":1244.5,"redirectEnd":0,"redirectStart":0,"requestStart":1244.5,"responseEnd":1954.4000000953674,"responseStart":1954.4000000953674,"secureConnectionStart":1244.5},{"duration":714.0999999046326,"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":1245,"connectEnd":1245,"connectStart":1245,"domainLookupEnd":1245,"domainLookupStart":1245,"fetchStart":1245,"redirectEnd":0,"redirectStart":0,"requestStart":1245,"responseEnd":1959.0999999046326,"responseStart":1959.0999999046326,"secureConnectionStart":1245}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":209,"responseStart":373,"responseEnd":382,"domLoading":376,"domInteractive":1928,"domContentLoadedEventStart":1928,"domContentLoadedEventEnd":1976,"domComplete":2524,"loadEventStart":2524,"loadEventEnd":2525,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1907.3000001907349},{"name":"bigPipe.sidebar-id.end","time":1908.3000001907349},{"name":"bigPipe.activity-panel-pipe-id.start","time":1908.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":1909.6999998092651},{"name":"activityTabFullyLoaded","time":1995.3000001907349}],"measures":[],"correlationId":"e6934ede919c9c","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":98,"dbReadsTimeInMs":11,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
The problem is incorrect used_tables() map of transformed expression.