The following query
SELECT a, COUNT(*) AS cnt
|
FROM t1 LEFT JOIN t2 ON (d = b)
|
WHERE a IN ( SELECT c FROM t2 WHERE b > 'k' )
|
GROUP BY a ORDER BY a, cnt LIMIT 2
|
on the test data returns 1 row if it's run with semijoin and join_cache_level > 4, and 2 rows otherwise. 2 rows is the correct result.
bzr version-info
revision-id: psergey@askmonty.org-20120705103901-9ero4x0eifk0wtks
|
date: 2012-07-05 14:39:01 +0400
|
build-date: 2012-07-11 01:54:42 +0400
|
revno: 3462
|
Also reproducible on maria/5.3 revno 3551, and on release builds 5.3.7 and 5.5.25.
Minimal optimizer_switch:
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,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
|
EXPLAIN (with the default optimizer_switch):
id select_type table type possible_keys key key_len ref rows filtered Extra
|
1 PRIMARY t1 index a a 4 NULL 3 100.00 Using where; Using temporary; Using filesort
|
1 PRIMARY t2 ref c c 5 test.t1.a 2 100.00 Using index; Start temporary; End temporary
|
1 PRIMARY t2 ref d d 2 test.t1.b 2 100.00 Using where; Using index
|
Warnings:
|
Note 1276 Field or reference 'test.t1.b' of SELECT #2 was resolved in SELECT #1
|
Note 1003 select `test`.`t1`.`a` AS `a`,count(0) AS `cnt` from `test`.`t1` semi join (`test`.`t2`) left join `test`.`t2` on(((`test`.`t2`.`d` = `test`.`t1`.`b`) and (`test`.`t1`.`b` is not null))) where ((`test`.`t2`.`c` = `test`.`t1`.`a`) and (`test`.`t1`.`b` > 'k')) group by `test`.`t1`.`a` order by `test`.`t1`.`a`,count(0) limit 2
|
Test case:
|
SET join_cache_level = 5;
|
SET optimizer_switch = 'semijoin=on';
|
|
CREATE TABLE t1 (a INT NOT NULL, b CHAR(1), KEY(a)) ENGINE=MyISAM;
|
INSERT INTO t1 VALUES (4,'p'),(1,'q'),(8,'e');
|
|
CREATE TABLE t2 (c INT, d CHAR(1), KEY(c), KEY(d)) ENGINE=MyISAM;
|
INSERT INTO t2 VALUES (4,'f'),(2,'i'),(5,'h'),(3,'q'),(1,'g');
|
|
SELECT a, COUNT(*) AS cnt
|
FROM t1 LEFT JOIN t2 ON (d = b)
|
WHERE a IN ( SELECT c FROM t2 WHERE b > 'k' )
|
GROUP BY a ORDER BY a, cnt LIMIT 2;
|
Expected result:
Actual result:
Please note that the aggregate function is not required, it just makes the test somewhat more sensible. The query can be modified like this (double a in ORDER BY is not a typo, it is needed for this version of the query):
SELECT a
|
FROM t1 LEFT JOIN t2 ON (d = b)
|
WHERE a IN ( SELECT c FROM t2 WHERE b > 'k' )
|
GROUP BY a ORDER BY a, a LIMIT 2;
|
It still returns 1 row instead of 2.
Note: I've set it to Minor, because join_cache_level > 4 is not default
{"report":{"fcp":727.8999998569489,"ttfb":129.89999985694885,"pageVisibility":"visible","entityId":12504,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"03b66dc0-97f7-470c-926d-d4a6cb3918fe","navigationType":0,"readyForUser":788.8999998569489,"redirectCount":0,"resourceLoadedEnd":913.5999999046326,"resourceLoadedStart":135.29999995231628,"resourceTiming":[{"duration":164.79999995231628,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":135.29999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":135.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":300.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":164.59999990463257,"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":135.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":135.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":300.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":173.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":135.70000004768372,"connectEnd":135.70000004768372,"connectStart":135.70000004768372,"domainLookupEnd":135.70000004768372,"domainLookupStart":135.70000004768372,"fetchStart":135.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":135.70000004768372,"responseEnd":309,"responseStart":309,"secureConnectionStart":135.70000004768372},{"duration":233.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":135.79999995231628,"connectEnd":135.79999995231628,"connectStart":135.79999995231628,"domainLookupEnd":135.79999995231628,"domainLookupStart":135.79999995231628,"fetchStart":135.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":135.79999995231628,"responseEnd":369.09999990463257,"responseStart":369.09999990463257,"secureConnectionStart":135.79999995231628},{"duration":236.90000009536743,"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":135.89999985694885,"connectEnd":135.89999985694885,"connectStart":135.89999985694885,"domainLookupEnd":135.89999985694885,"domainLookupStart":135.89999985694885,"fetchStart":135.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":135.89999985694885,"responseEnd":372.7999999523163,"responseStart":372.7999999523163,"secureConnectionStart":135.89999985694885},{"duration":237.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":136,"connectEnd":136,"connectStart":136,"domainLookupEnd":136,"domainLookupStart":136,"fetchStart":136,"redirectEnd":0,"redirectStart":0,"requestStart":136,"responseEnd":373.2000000476837,"responseStart":373.2000000476837,"secureConnectionStart":136},{"duration":237.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":136.09999990463257,"connectEnd":136.09999990463257,"connectStart":136.09999990463257,"domainLookupEnd":136.09999990463257,"domainLookupStart":136.09999990463257,"fetchStart":136.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":136.09999990463257,"responseEnd":373.59999990463257,"responseStart":373.59999990463257,"secureConnectionStart":136.09999990463257},{"duration":237.89999985694885,"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":136.20000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":136.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":374.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":238,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":136.20000004768372,"connectEnd":136.20000004768372,"connectStart":136.20000004768372,"domainLookupEnd":136.20000004768372,"domainLookupStart":136.20000004768372,"fetchStart":136.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":136.20000004768372,"responseEnd":374.2000000476837,"responseStart":374.2000000476837,"secureConnectionStart":136.20000004768372},{"duration":238.09999990463257,"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":136.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":136.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":374.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":238.29999995231628,"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":136.5,"connectEnd":136.5,"connectStart":136.5,"domainLookupEnd":136.5,"domainLookupStart":136.5,"fetchStart":136.5,"redirectEnd":0,"redirectStart":0,"requestStart":136.5,"responseEnd":374.7999999523163,"responseStart":374.7999999523163,"secureConnectionStart":136.5},{"duration":687.4000000953674,"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":137.09999990463257,"connectEnd":137.09999990463257,"connectStart":137.09999990463257,"domainLookupEnd":137.09999990463257,"domainLookupStart":137.09999990463257,"fetchStart":137.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":137.09999990463257,"responseEnd":824.5,"responseStart":824.5,"secureConnectionStart":137.09999990463257},{"duration":776.3999998569489,"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":137.20000004768372,"connectEnd":137.20000004768372,"connectStart":137.20000004768372,"domainLookupEnd":137.20000004768372,"domainLookupStart":137.20000004768372,"fetchStart":137.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":137.20000004768372,"responseEnd":913.5999999046326,"responseStart":913.5999999046326,"secureConnectionStart":137.20000004768372},{"duration":372.69999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":538.2000000476837,"connectEnd":538.2000000476837,"connectStart":538.2000000476837,"domainLookupEnd":538.2000000476837,"domainLookupStart":538.2000000476837,"fetchStart":538.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":538.2000000476837,"responseEnd":910.8999998569489,"responseStart":910.8999998569489,"secureConnectionStart":538.2000000476837},{"duration":255,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":707.3999998569489,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":707.3999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":962.3999998569489,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":2,"responseStart":130,"responseEnd":133,"domLoading":133,"domInteractive":933,"domContentLoadedEventStart":933,"domContentLoadedEventEnd":968,"domComplete":1746,"loadEventStart":1746,"loadEventEnd":1748,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":915.8999998569489},{"name":"bigPipe.sidebar-id.end","time":916.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.start","time":916.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":919.0999999046326},{"name":"activityTabFullyLoaded","time":973.7000000476837}],"measures":[],"correlationId":"4c5d876e5c79fd","effectiveType":"4g","downlink":9.6,"rtt":0,"serverDuration":69,"dbReadsTimeInMs":8,"dbConnsTimeInMs":14,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}