The following query (initially submitted as MDEV-765):
SELECT MIN(a), b
|
FROM t1
|
WHERE a > ( SELECT a FROM t2 WHERE a = 0 )
|
GROUP BY b;
|
does not return as many rows as if the subquery is replaced with a constant.
explain:
id select_type table type possible_keys key key_len ref rows Extra
|
1 PRIMARY t1 range NULL b 10 NULL 10 Using where; Using index for group-by
|
2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where
|
optimizer switch:
index_merge=on,
|
index_merge_union=on,
|
index_merge_sort_union=on,
|
index_merge_intersection=on,
|
index_merge_sort_intersection=off,
|
index_condition_pushdown=off,
|
derived_merge=off,
|
derived_with_keys=off,
|
firstmatch=off,
|
loosescan=off,
|
materialization=off,
|
in_to_exists=on,
|
semijoin=off,
|
partial_match_rowid_merge=on,
|
partial_match_table_scan=on,
|
subquery_cache=off,
|
mrr=off,
|
mrr_cost_based=off,
|
mrr_sort_keys=off,
|
outer_join_with_cache=off,
|
semijoin_with_cache=off,
|
join_cache_incremental=on,
|
join_cache_hashed=on,
|
join_cache_bka=on,
|
optimize_join_buffer_size=off,
|
table_elimination=on
|
test case:
CREATE TABLE t1 (a int, b int, KEY (b, a)) ;
|
INSERT INTO t1 VALUES (0,99),(9,99),(4,0),(7,0),(99,0),(7,0),(8,0),(99,0),(1,0);
|
CREATE TABLE t2 (c int) ;
|
INSERT INTO t2 VALUES (0),(1);
|
SELECT MIN(a), b FROM t1 WHERE a > ( SELECT c FROM t2 WHERE c = 0 ) GROUP BY b;
|
returns:
SELECT MIN(a), b
|
FROM t1
|
WHERE a > 0
|
GROUP BY b;
|
returns:
bzr version-info:
|
|
date: 2011-08-11 22:34:41 -0700
|
build-date: 2011-08-12 12:20:36 +0300
|
revno: 3151
|
branch-nick: maria-5.3
|
Repeatable on maria-5.3. Not repeatable on maria-5.2. Not repeatable with other subquery operators.
To repeat on 5.5 one needs that the subquery is expensive, that is, it must examine >100 rows.
{"report":{"fcp":699.2999999523163,"ttfb":185.39999985694885,"pageVisibility":"visible","entityId":22820,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"5e54be18-dfcd-48e9-bb59-53905b51fd26","navigationType":0,"readyForUser":809.8999998569489,"redirectCount":0,"resourceLoadedEnd":860.8999998569489,"resourceLoadedStart":190.79999995231628,"resourceTiming":[{"duration":13.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":190.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":190.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":204.29999995231628,"responseStart":0,"secureConnectionStart":0},{"duration":22.799999952316284,"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":191,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":191,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":213.79999995231628,"responseStart":0,"secureConnectionStart":0},{"duration":80.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":191.09999990463257,"connectEnd":191.09999990463257,"connectStart":191.09999990463257,"domainLookupEnd":191.09999990463257,"domainLookupStart":191.09999990463257,"fetchStart":191.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":191.09999990463257,"responseEnd":271.59999990463257,"responseStart":271.59999990463257,"secureConnectionStart":191.09999990463257},{"duration":154.19999980926514,"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":191.20000004768372,"connectEnd":191.20000004768372,"connectStart":191.20000004768372,"domainLookupEnd":191.20000004768372,"domainLookupStart":191.20000004768372,"fetchStart":191.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":191.20000004768372,"responseEnd":345.39999985694885,"responseStart":345.39999985694885,"secureConnectionStart":191.20000004768372},{"duration":157.60000014305115,"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":191.39999985694885,"connectEnd":191.39999985694885,"connectStart":191.39999985694885,"domainLookupEnd":191.39999985694885,"domainLookupStart":191.39999985694885,"fetchStart":191.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":191.39999985694885,"responseEnd":349,"responseStart":349,"secureConnectionStart":191.39999985694885},{"duration":158.09999990463257,"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":191.5,"connectEnd":191.5,"connectStart":191.5,"domainLookupEnd":191.5,"domainLookupStart":191.5,"fetchStart":191.5,"redirectEnd":0,"redirectStart":0,"requestStart":191.5,"responseEnd":349.59999990463257,"responseStart":349.59999990463257,"secureConnectionStart":191.5},{"duration":158.60000014305115,"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":191.59999990463257,"connectEnd":191.59999990463257,"connectStart":191.59999990463257,"domainLookupEnd":191.59999990463257,"domainLookupStart":191.59999990463257,"fetchStart":191.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":191.59999990463257,"responseEnd":350.2000000476837,"responseStart":350.2000000476837,"secureConnectionStart":191.59999990463257},{"duration":158.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":191.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":191.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":350.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":158.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":191.79999995231628,"connectEnd":191.79999995231628,"connectStart":191.79999995231628,"domainLookupEnd":191.79999995231628,"domainLookupStart":191.79999995231628,"fetchStart":191.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":191.79999995231628,"responseEnd":350.59999990463257,"responseStart":350.59999990463257,"secureConnectionStart":191.79999995231628},{"duration":159.30000019073486,"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":191.89999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":191.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":351.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":159.5,"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":191.89999985694885,"connectEnd":191.89999985694885,"connectStart":191.89999985694885,"domainLookupEnd":191.89999985694885,"domainLookupStart":191.89999985694885,"fetchStart":191.89999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":191.89999985694885,"responseEnd":351.39999985694885,"responseStart":351.39999985694885,"secureConnectionStart":191.89999985694885},{"duration":438.90000009536743,"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":197.29999995231628,"connectEnd":197.29999995231628,"connectStart":197.29999995231628,"domainLookupEnd":197.29999995231628,"domainLookupStart":197.29999995231628,"fetchStart":197.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":197.29999995231628,"responseEnd":636.2000000476837,"responseStart":636.2000000476837,"secureConnectionStart":197.29999995231628},{"duration":459.7000000476837,"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":197.39999985694885,"connectEnd":197.39999985694885,"connectStart":197.39999985694885,"domainLookupEnd":197.39999985694885,"domainLookupStart":197.39999985694885,"fetchStart":197.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":197.39999985694885,"responseEnd":657.0999999046326,"responseStart":657.0999999046326,"secureConnectionStart":197.39999985694885},{"duration":156.80000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":486.39999985694885,"connectEnd":486.39999985694885,"connectStart":486.39999985694885,"domainLookupEnd":486.39999985694885,"domainLookupStart":486.39999985694885,"fetchStart":486.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":486.39999985694885,"responseEnd":643.2000000476837,"responseStart":643.2000000476837,"secureConnectionStart":486.39999985694885},{"duration":7.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":661.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":661.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":669.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":122.09999990463257,"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":738.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":738.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":860.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":121.89999985694885,"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":739,"connectEnd":739,"connectStart":739,"domainLookupEnd":739,"domainLookupStart":739,"fetchStart":739,"redirectEnd":0,"redirectStart":0,"requestStart":739,"responseEnd":860.8999998569489,"responseStart":860.8999998569489,"secureConnectionStart":739},{"duration":153.70000004768372,"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":739.5,"connectEnd":739.5,"connectStart":739.5,"domainLookupEnd":739.5,"domainLookupStart":739.5,"fetchStart":739.5,"redirectEnd":0,"redirectStart":0,"requestStart":739.5,"responseEnd":893.2000000476837,"responseStart":893.2000000476837,"secureConnectionStart":739.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":50,"responseStart":185,"responseEnd":193,"domLoading":189,"domInteractive":869,"domContentLoadedEventStart":869,"domContentLoadedEventEnd":905,"domComplete":1425,"loadEventStart":1425,"loadEventEnd":1426,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":849.7000000476837},{"name":"bigPipe.sidebar-id.end","time":850.3999998569489},{"name":"bigPipe.activity-panel-pipe-id.start","time":850.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":851.3999998569489},{"name":"activityTabFullyLoaded","time":921.0999999046326}],"measures":[],"correlationId":"b3f9f80d9553c2","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":75,"dbReadsTimeInMs":14,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
pushed to 5.3