The following test case
SET optimizer_switch = 'derived_merge=on,in_to_exists=on';
|
|
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
|
INSERT INTO t1 VALUES (4),(8);
|
|
CREATE TABLE t2 (b INT) ENGINE=MyISAM;
|
INSERT INTO t2 VALUES (7),(0);
|
|
CREATE TABLE t3 (c INT, d INT NOT NULL) ENGINE=MyISAM;
|
INSERT INTO t3 VALUES (0,4),(8,6);
|
|
SELECT * FROM t1
|
WHERE a >= ALL (
|
SELECT d FROM t2 LEFT JOIN ( SELECT * FROM t3 ) AS alias ON ( c = b )
|
WHERE b >= a
|
);
|
returns 2 rows:
The same query without the inner subquery returns only one row:
SELECT * FROM t1
|
WHERE a >= ALL ( SELECT d FROM t2 LEFT JOIN t3 ON ( c = b ) WHERE b >= a );
|
a
|
---
|
8
|
A query with a view instead of the inner subquery also returns one row:
CREATE ALGORITHM=MERGE VIEW v AS SELECT * FROM t3;
|
SELECT * FROM t1 WHERE a >= ALL (
|
SELECT d FROM t2 LEFT JOIN v ON ( c = b )
|
WHERE b >= a
|
);
|
a
|
---
|
8
|
CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v AS SELECT * FROM t3;
|
SELECT * FROM t1 WHERE a >= ALL (
|
SELECT d FROM t2 LEFT JOIN v ON ( c = b )
|
WHERE b >= a
|
);
|
a
|
---
|
8
|
1 row is the correct result.
branch: maria/5.3
|
revision-id: sergii@pisem.net-20121123121131-p4nfv8j2cbh68dbg
|
date: 2012-11-23 13:11:31 +0100
|
revno: 3605
|
On maria/5.3 the problem appeared with revno 3592 (Merge MariaDB 5.1.66 -> 5.2 -> 5.3).
Also reproducible on maria/5.5, maria/10.0.
MySQL 5.6 returns the correct result.
Minimal optimizer_switch: derived_merge=on,in_to_exists=on
Full optimizer_switch (default):
index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=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
|
EXPLAIN (with the default optimizer_switch):
EXPLAIN EXTENDED
|
SELECT * FROM t1
|
WHERE a >= ALL (
|
SELECT d FROM t2 LEFT JOIN ( SELECT * FROM t3 ) AS alias ON ( c = b )
|
WHERE b >= a
|
);
|
id select_type table type possible_keys key key_len ref rows filtered Extra
|
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
|
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2100.00 Using where
|
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 2100.00 Using where; Using join buffer (flat, BNL join)
|
Warnings:
|
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
|
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <not>(<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(select `test`.`t3`.`d` from `test`.`t2` left join (`test`.`t3`) on((`test`.`t3`.`c` = `test`.`t2`.`b`)) where ((`test`.`t2`.`b` >= `test`.`t1`.`a`) and trigcond((<cache>(`test`.`t1`.`a`) < `test`.`t3`.`d`)))))))
|
Setting it to Minor for now as it can be considered an edge case.
{"report":{"fcp":678.6000001430511,"ttfb":143.5,"pageVisibility":"visible","entityId":22201,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"6fa39d7d-ff5b-42dd-b6c6-5b766b52b3a8","navigationType":0,"readyForUser":753.5,"redirectCount":0,"resourceLoadedEnd":588.1000001430511,"resourceLoadedStart":149.70000004768372,"resourceTiming":[{"duration":10.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":149.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":149.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":160.20000004768372,"responseStart":0,"secureConnectionStart":0},{"duration":10.700000047683716,"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":150.10000014305115,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":150.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":160.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":65.20000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":150.20000004768372,"connectEnd":150.20000004768372,"connectStart":150.20000004768372,"domainLookupEnd":150.20000004768372,"domainLookupStart":150.20000004768372,"fetchStart":150.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":150.20000004768372,"responseEnd":215.40000009536743,"responseStart":215.40000009536743,"secureConnectionStart":150.20000004768372},{"duration":143.29999995231628,"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":150.30000019073486,"connectEnd":150.30000019073486,"connectStart":150.30000019073486,"domainLookupEnd":150.30000019073486,"domainLookupStart":150.30000019073486,"fetchStart":150.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":150.30000019073486,"responseEnd":293.60000014305115,"responseStart":293.60000014305115,"secureConnectionStart":150.30000019073486},{"duration":146.70000004768372,"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":150.5,"connectEnd":150.5,"connectStart":150.5,"domainLookupEnd":150.5,"domainLookupStart":150.5,"fetchStart":150.5,"redirectEnd":0,"redirectStart":0,"requestStart":150.5,"responseEnd":297.2000000476837,"responseStart":297.2000000476837,"secureConnectionStart":150.5},{"duration":148.20000004768372,"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":150.5,"connectEnd":150.5,"connectStart":150.5,"domainLookupEnd":150.5,"domainLookupStart":150.5,"fetchStart":150.5,"redirectEnd":0,"redirectStart":0,"requestStart":150.5,"responseEnd":298.7000000476837,"responseStart":298.7000000476837,"secureConnectionStart":150.5},{"duration":149.70000004768372,"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":150.5,"connectEnd":150.5,"connectStart":150.5,"domainLookupEnd":150.5,"domainLookupStart":150.5,"fetchStart":150.5,"redirectEnd":0,"redirectStart":0,"requestStart":150.5,"responseEnd":300.2000000476837,"responseStart":300.2000000476837,"secureConnectionStart":150.5},{"duration":151,"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":150.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":150.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":301.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":150.89999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":150.80000019073486,"connectEnd":150.80000019073486,"connectStart":150.80000019073486,"domainLookupEnd":150.80000019073486,"domainLookupStart":150.80000019073486,"fetchStart":150.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":150.80000019073486,"responseEnd":301.7000000476837,"responseStart":301.7000000476837,"secureConnectionStart":150.80000019073486},{"duration":152.20000004768372,"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":150.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":150.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":303.10000014305115,"responseStart":0,"secureConnectionStart":0},{"duration":152.20000004768372,"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":151.10000014305115,"connectEnd":151.10000014305115,"connectStart":151.10000014305115,"domainLookupEnd":151.10000014305115,"domainLookupStart":151.10000014305115,"fetchStart":151.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":151.10000014305115,"responseEnd":303.30000019073486,"responseStart":303.30000019073486,"secureConnectionStart":151.10000014305115},{"duration":425.40000009536743,"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":151.70000004768372,"connectEnd":151.70000004768372,"connectStart":151.70000004768372,"domainLookupEnd":151.70000004768372,"domainLookupStart":151.70000004768372,"fetchStart":151.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":151.70000004768372,"responseEnd":577.1000001430511,"responseStart":577.1000001430511,"secureConnectionStart":151.70000004768372},{"duration":436.2999999523163,"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":151.80000019073486,"connectEnd":151.80000019073486,"connectStart":151.80000019073486,"domainLookupEnd":151.80000019073486,"domainLookupStart":151.80000019073486,"fetchStart":151.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":151.80000019073486,"responseEnd":588.1000001430511,"responseStart":588.1000001430511,"secureConnectionStart":151.80000019073486},{"duration":155.59999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":428.90000009536743,"connectEnd":428.90000009536743,"connectStart":428.90000009536743,"domainLookupEnd":428.90000009536743,"domainLookupStart":428.90000009536743,"fetchStart":428.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":428.90000009536743,"responseEnd":584.5,"responseStart":584.5,"secureConnectionStart":428.90000009536743},{"duration":2,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":600.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":600.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":602.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":164,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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","startTime":676.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":676.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":840.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":163.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/50bc9be5bfead1a25e72c1a9338c94f6-CDN/lu2bu7/820016/12ta74/e108c7645258ccb43280ed3404e3e949/_/download/contextbatch/css/com.atlassian.jira.plugins.jira-development-integration-plugin:0,-_super,-jira.view.issue,-jira.global,-jira.general,-jira.browse.project,-project.issue.navigator,-atl.general/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":676.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":676.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":840.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":164.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/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","startTime":677.5,"connectEnd":677.5,"connectStart":677.5,"domainLookupEnd":677.5,"domainLookupStart":677.5,"fetchStart":677.5,"redirectEnd":0,"redirectStart":0,"requestStart":677.5,"responseEnd":842.4000000953674,"responseStart":842.4000000953674,"secureConnectionStart":677.5},{"duration":168.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/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","startTime":678,"connectEnd":678,"connectStart":678,"domainLookupEnd":678,"domainLookupStart":678,"fetchStart":678,"redirectEnd":0,"redirectStart":0,"requestStart":678,"responseEnd":846.9000000953674,"responseStart":846.9000000953674,"secureConnectionStart":678},{"duration":170.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/86ee9bbc76cd1bcd8556fcdcf46241c9-CDN/lu2bu7/820016/12ta74/e108c7645258ccb43280ed3404e3e949/_/download/contextbatch/js/com.atlassian.jira.plugins.jira-development-integration-plugin:0,-_super,-jira.view.issue,-jira.global,-jira.general,-jira.browse.project,-project.issue.navigator,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":678.4000000953674,"connectEnd":678.4000000953674,"connectStart":678.4000000953674,"domainLookupEnd":678.4000000953674,"domainLookupStart":678.4000000953674,"fetchStart":678.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":678.4000000953674,"responseEnd":849,"responseStart":849,"secureConnectionStart":678.4000000953674}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":7,"responseStart":144,"responseEnd":147,"domLoading":147,"domInteractive":811,"domContentLoadedEventStart":811,"domContentLoadedEventEnd":847,"domComplete":1117,"loadEventStart":1117,"loadEventEnd":1117,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":793.7000000476837},{"name":"bigPipe.sidebar-id.end","time":794.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":794.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":795.6000001430511},{"name":"activityTabFullyLoaded","time":863.1000001430511}],"measures":[],"correlationId":"fcf6f8a7bfee03","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":77,"dbReadsTimeInMs":13,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Change in sql/item_subselect.cc from this commit seems to trigger this bug:
http://bazaar.launchpad.net/~mysql/mysql-server/5.1/revision/3792