-
Bug
-
-
Critical
-
Resolution:
Fixed
-
None
-
-
-
Consider the following database tables:
create table t0 (a int);
|
insert into t0 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
|
create table t1 (a int);
|
insert into t1 select (t0.a-1)*10 + (t.a-1) + 1 from t0 t, t0;
|
create table t2 (a int);
|
insert into t2 values (12), (88), (47), (33), (28);
|
The following query uses very inefficient execution plan without look-ups into the materialized subquery:
select * from t1 where a in (select a from t2 group by a);
|
MariaDB [test]> explain extended select * from t1 where a in (select a from t2 group by a);
|
+------+--------------+-------------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+--------------+-------------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
| 1 | PRIMARY | <subquery2> | ALL | distinct_key | NULL | NULL | NULL | 5 | 100.00 | |
|
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 100 | 100.00 | Using where; Using join buffer (flat, BNL join) |
|
| 2 | MATERIALIZED | t2 | ALL | NULL | NULL | NULL | NULL | 5 | 100.00 | |
|
+------+--------------+-------------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
3 rows in set, 1 warning (0.00 sec)
|
|
MariaDB [test]> show warnings;
|
+-------+------+------------------------------------------------------------------------------------------------------------------+
|
| Level | Code | Message |
|
+-------+------+------------------------------------------------------------------------------------------------------------------+
|
| Note | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where (`test`.`t1`.`a` = `test`.`t2`.`a`) |
|
+-------+------+------------------------------------------------------------------------------------------------------------------+
|
1 row in set (0.00 sec)
|
The same problem we observe for the mergeable semi-join subquery
MariaDB [test]> explain extended select * from t1 where a in (select a from t2);
|
+------+--------------+-------------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+--------------+-------------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
| 1 | PRIMARY | <subquery2> | ALL | distinct_key | NULL | NULL | NULL | 5 | 100.00 | |
|
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 100 | 100.00 | Using where; Using join buffer (flat, BNL join) |
|
| 2 | MATERIALIZED | t2 | ALL | NULL | NULL | NULL | NULL | 5 | 100.00 | |
|
+------+--------------+-------------+------+---------------+------+---------+------+------+----------+-------------------------------------------------+
|
This becomes a real problem when t1 and t2 are 100 times bigger.
{"report":{"fcp":756.3999996185303,"ttfb":176.30000019073486,"pageVisibility":"visible","entityId":77683,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"de5401ab-7190-4a6d-b47f-a15944851f80","navigationType":0,"readyForUser":838.3999996185303,"redirectCount":0,"resourceLoadedEnd":782.0999994277954,"resourceLoadedStart":182.89999961853027,"resourceTiming":[{"duration":11.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":182.89999961853027,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.89999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":194.39999961853027,"responseStart":0,"secureConnectionStart":0},{"duration":11.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":183.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":183.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":194.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":71.89999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":183.30000019073486,"connectEnd":183.30000019073486,"connectStart":183.30000019073486,"domainLookupEnd":183.30000019073486,"domainLookupStart":183.30000019073486,"fetchStart":183.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":183.30000019073486,"responseEnd":255.19999980926514,"responseStart":255.19999980926514,"secureConnectionStart":183.30000019073486},{"duration":112.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":183.5,"connectEnd":183.5,"connectStart":183.5,"domainLookupEnd":183.5,"domainLookupStart":183.5,"fetchStart":183.5,"redirectEnd":0,"redirectStart":0,"requestStart":183.5,"responseEnd":296.19999980926514,"responseStart":296.19999980926514,"secureConnectionStart":183.5},{"duration":117.09999942779541,"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":183.80000019073486,"connectEnd":183.80000019073486,"connectStart":183.80000019073486,"domainLookupEnd":183.80000019073486,"domainLookupStart":183.80000019073486,"fetchStart":183.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":183.80000019073486,"responseEnd":300.8999996185303,"responseStart":300.8999996185303,"secureConnectionStart":183.80000019073486},{"duration":117.5,"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":184,"connectEnd":184,"connectStart":184,"domainLookupEnd":184,"domainLookupStart":184,"fetchStart":184,"redirectEnd":0,"redirectStart":0,"requestStart":184,"responseEnd":301.5,"responseStart":301.3999996185303,"secureConnectionStart":184},{"duration":117.70000076293945,"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":184.0999994277954,"connectEnd":184.0999994277954,"connectStart":184.0999994277954,"domainLookupEnd":184.0999994277954,"domainLookupStart":184.0999994277954,"fetchStart":184.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":184.0999994277954,"responseEnd":301.80000019073486,"responseStart":301.80000019073486,"secureConnectionStart":184.0999994277954},{"duration":216,"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":184.39999961853027,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":184.39999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":400.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":117.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":184.5,"connectEnd":184.5,"connectStart":184.5,"domainLookupEnd":184.5,"domainLookupStart":184.5,"fetchStart":184.5,"redirectEnd":0,"redirectStart":0,"requestStart":184.5,"responseEnd":302.30000019073486,"responseStart":302.30000019073486,"secureConnectionStart":184.5},{"duration":215.89999961853027,"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":184.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":184.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":400.5999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":118.09999942779541,"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":184.80000019073486,"connectEnd":184.80000019073486,"connectStart":184.80000019073486,"domainLookupEnd":184.80000019073486,"domainLookupStart":184.80000019073486,"fetchStart":184.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":184.80000019073486,"responseEnd":302.8999996185303,"responseStart":302.8999996185303,"secureConnectionStart":184.80000019073486},{"duration":224.69999980926514,"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":185.80000019073486,"connectEnd":185.80000019073486,"connectStart":185.80000019073486,"domainLookupEnd":185.80000019073486,"domainLookupStart":185.80000019073486,"fetchStart":185.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":185.80000019073486,"responseEnd":410.5,"responseStart":410.5,"secureConnectionStart":185.80000019073486},{"duration":261.4000005722046,"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":185.89999961853027,"connectEnd":185.89999961853027,"connectStart":185.89999961853027,"domainLookupEnd":185.89999961853027,"domainLookupStart":185.89999961853027,"fetchStart":185.89999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":185.89999961853027,"responseEnd":447.30000019073486,"responseStart":447.30000019073486,"secureConnectionStart":185.89999961853027},{"duration":19.800000190734863,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":428.5999994277954,"connectEnd":428.5999994277954,"connectStart":428.5999994277954,"domainLookupEnd":428.5999994277954,"domainLookupStart":428.5999994277954,"fetchStart":428.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":428.5999994277954,"responseEnd":448.3999996185303,"responseStart":448.3999996185303,"secureConnectionStart":428.5999994277954},{"duration":217,"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","startTime":452.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":452.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":669.5,"responseStart":0,"secureConnectionStart":0},{"duration":321.19999980926514,"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","startTime":453.5,"connectEnd":453.5,"connectStart":453.5,"domainLookupEnd":453.5,"domainLookupStart":453.5,"fetchStart":453.5,"redirectEnd":0,"redirectStart":0,"requestStart":453.5,"responseEnd":774.6999998092651,"responseStart":774.6999998092651,"secureConnectionStart":453.5},{"duration":328.29999923706055,"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","startTime":453.80000019073486,"connectEnd":453.80000019073486,"connectStart":453.80000019073486,"domainLookupEnd":453.80000019073486,"domainLookupStart":453.80000019073486,"fetchStart":453.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":453.80000019073486,"responseEnd":782.0999994277954,"responseStart":782.0999994277954,"secureConnectionStart":453.80000019073486},{"duration":130.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":746.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":746.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":877.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":127.09999942779541,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":760.3000001907349,"connectEnd":760.3000001907349,"connectStart":760.3000001907349,"domainLookupEnd":760.3000001907349,"domainLookupStart":760.3000001907349,"fetchStart":760.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":760.3000001907349,"responseEnd":887.3999996185303,"responseStart":887.3999996185303,"secureConnectionStart":760.3000001907349},{"duration":2.6999998092651367,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":896.6999998092651,"connectEnd":896.6999998092651,"connectStart":896.6999998092651,"domainLookupEnd":896.6999998092651,"domainLookupStart":896.6999998092651,"fetchStart":896.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":896.6999998092651,"responseEnd":899.3999996185303,"responseStart":899.3999996185303,"secureConnectionStart":896.6999998092651}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":3,"responseStart":177,"responseEnd":179,"domLoading":181,"domInteractive":916,"domContentLoadedEventStart":916,"domContentLoadedEventEnd":968,"domComplete":1273,"loadEventStart":1273,"loadEventEnd":1274,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":879.1999998092651},{"name":"bigPipe.sidebar-id.end","time":880.0999994277954},{"name":"bigPipe.activity-panel-pipe-id.start","time":880.1999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":882.5999994277954},{"name":"activityTabFullyLoaded","time":989.5}],"measures":[],"correlationId":"e26ecf725acb47","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":106,"dbReadsTimeInMs":11,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}