Materialization strategy is not used for REPLACE ... SELECT. Filing this based on CSC#8345.
create table t1 (a int, b int, c int);
|
insert into t1 select a,a,a from test.one_k A;
|
|
create table t2 (a int, b int, c int);
|
|
insert into t2 select A.a, A.a, A.a from test.one_k A;
|
insert into t2 select * from t2;
|
insert into t2 select * from t2;
|
insert into t2 select * from t2;
|
insert into t2 select * from t2;
|
Let's make a query with a subquery that is better executed with Materialization:
explain
|
select * from t1 where (a,b) in (select max(a),b from t2 group by b);
|
+------+--------------+-------------+--------+---------------+--------------+---------+-------------------+-------+-----------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+--------------+-------------+--------+---------------+--------------+---------+-------------------+-------+-----------------+
|
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 1000 | Using where |
|
| 1 | PRIMARY | <subquery2> | eq_ref | distinct_key | distinct_key | 8 | j12.t1.a,j12.t1.b | 1 | |
|
| 2 | MATERIALIZED | t2 | ALL | NULL | NULL | NULL | NULL | 16000 | Using temporary |
|
+------+--------------+-------------+--------+---------------+--------------+---------+-------------------+-------+-----------------+
|
Ok.
Now, let's run a REPLACE ... SELECT for it:
create table t3 as select * from t1 limit 1;
|
|
replace into t3
|
select * from t1 where (a,b) in (select max(a),b from t2 group by b);
|
|
# Query OK, 1000 rows affected (3 min 30.18 sec)
|
# Records: 1000 Duplicates: 0 Warnings: 0
|
3 min looks like it is too long for the above EXPLAIN plan. Indeed, SHOW EXPLAIN shows:
MariaDB [(none)]> show explain for 2;
|
+------+--------------------+-------+------+---------------+------+---------+------+-------+-----------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+--------------------+-------+------+---------------+------+---------+------+-------+-----------------+
|
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 1000 | Using where |
|
| 2 | DEPENDENT SUBQUERY | t2 | ALL | NULL | NULL | NULL | NULL | 15794 | Using temporary |
|
+------+--------------------+-------+------+---------------+------+---------+------+-------+-----------------+
|
It is using IN->EXISTS conversion, not materialization.
CREATE TABLE ... SELECT is not affected:
MariaDB [j12]> create table tmp1 as select * from t1 where (a,b) in (select max(a),b from t2 group by b);
|
Query OK, 1000 rows affected (0.84 sec)
|
Records: 1000 Duplicates: 0 Warnings: 0
|
- relates to
-
MDEV-7215
EXPLAIN REPLACE produces an error: Column count doesn't match value count
-
-
Closed
{"report":{"fcp":1600.5999999046326,"ttfb":547.5999999046326,"pageVisibility":"visible","entityId":49140,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"a45aaea8-6e64-4d31-8a38-0c3d5720d2ee","navigationType":0,"readyForUser":1686.5,"redirectCount":0,"resourceLoadedEnd":2771.0999999046326,"resourceLoadedStart":605.3999996185303,"resourceTiming":[{"duration":364,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":605.3999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":605.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":969.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":383.09999990463257,"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":605.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":605.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":988.7999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":438.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":605.8999996185303,"connectEnd":605.8999996185303,"connectStart":605.8999996185303,"domainLookupEnd":605.8999996185303,"domainLookupStart":605.8999996185303,"fetchStart":605.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":605.8999996185303,"responseEnd":1044.5999999046326,"responseStart":1044.5999999046326,"secureConnectionStart":605.8999996185303},{"duration":564.4000000953674,"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":606.0999999046326,"connectEnd":606.0999999046326,"connectStart":606.0999999046326,"domainLookupEnd":606.0999999046326,"domainLookupStart":606.0999999046326,"fetchStart":606.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":606.0999999046326,"responseEnd":1170.5,"responseStart":1170.5,"secureConnectionStart":606.0999999046326},{"duration":568.5999999046326,"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":606.2999997138977,"connectEnd":606.2999997138977,"connectStart":606.2999997138977,"domainLookupEnd":606.2999997138977,"domainLookupStart":606.2999997138977,"fetchStart":606.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":606.2999997138977,"responseEnd":1174.8999996185303,"responseStart":1174.8999996185303,"secureConnectionStart":606.2999997138977},{"duration":569.0999999046326,"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":606.5,"connectEnd":606.5,"connectStart":606.5,"domainLookupEnd":606.5,"domainLookupStart":606.5,"fetchStart":606.5,"redirectEnd":0,"redirectStart":0,"requestStart":606.5,"responseEnd":1175.5999999046326,"responseStart":1175.5999999046326,"secureConnectionStart":606.5},{"duration":569.3000001907349,"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":606.6999998092651,"connectEnd":606.6999998092651,"connectStart":606.6999998092651,"domainLookupEnd":606.6999998092651,"domainLookupStart":606.6999998092651,"fetchStart":606.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":606.6999998092651,"responseEnd":1176,"responseStart":1176,"secureConnectionStart":606.6999998092651},{"duration":615.3000001907349,"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":606.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":606.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1222.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":569.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":607.0999999046326,"connectEnd":607.0999999046326,"connectStart":607.0999999046326,"domainLookupEnd":607.0999999046326,"domainLookupStart":607.0999999046326,"fetchStart":607.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":607.0999999046326,"responseEnd":1176.5999999046326,"responseStart":1176.5999999046326,"secureConnectionStart":607.0999999046326},{"duration":615.1999998092651,"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":607.1999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":607.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1222.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":569.9000000953674,"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":607.3999996185303,"connectEnd":607.3999996185303,"connectStart":607.3999996185303,"domainLookupEnd":607.3999996185303,"domainLookupStart":607.3999996185303,"fetchStart":607.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":607.3999996185303,"responseEnd":1177.2999997138977,"responseStart":1177.2999997138977,"secureConnectionStart":607.3999996185303},{"duration":1030.6999998092651,"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":608.1999998092651,"connectEnd":608.1999998092651,"connectStart":608.1999998092651,"domainLookupEnd":608.1999998092651,"domainLookupStart":608.1999998092651,"fetchStart":608.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":608.1999998092651,"responseEnd":1638.8999996185303,"responseStart":1638.8999996185303,"secureConnectionStart":608.1999998092651},{"duration":2162.800000190735,"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":608.2999997138977,"connectEnd":608.2999997138977,"connectStart":608.2999997138977,"domainLookupEnd":608.2999997138977,"domainLookupStart":608.2999997138977,"fetchStart":608.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":608.2999997138977,"responseEnd":2771.0999999046326,"responseStart":2771.0999999046326,"secureConnectionStart":608.2999997138977},{"duration":421.7999997138977,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1236.5,"connectEnd":1236.5,"connectStart":1236.5,"domainLookupEnd":1236.5,"domainLookupStart":1236.5,"fetchStart":1236.5,"redirectEnd":0,"redirectStart":0,"requestStart":1236.5,"responseEnd":1658.2999997138977,"responseStart":1658.2999997138977,"secureConnectionStart":1236.5},{"duration":1169.1999998092651,"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":1756.5,"connectEnd":1756.5,"connectStart":1756.5,"domainLookupEnd":1756.5,"domainLookupStart":1756.5,"fetchStart":1756.5,"redirectEnd":0,"redirectStart":0,"requestStart":1756.5,"responseEnd":2925.699999809265,"responseStart":2925.699999809265,"secureConnectionStart":1756.5}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":379,"responseStart":548,"responseEnd":602,"domLoading":602,"domInteractive":2809,"domContentLoadedEventStart":2809,"domContentLoadedEventEnd":2885,"domComplete":3419,"loadEventStart":3419,"loadEventEnd":3419,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2773.0999999046326},{"name":"bigPipe.sidebar-id.end","time":2774},{"name":"bigPipe.activity-panel-pipe-id.start","time":2774.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":2777.3999996185303},{"name":"activityTabFullyLoaded","time":2926.8999996185303}],"measures":[],"correlationId":"5338ccc58ba2ca","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":108,"dbReadsTimeInMs":15,"dbConnsTimeInMs":24,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
elenst, could you run tests with the above commit (it is for current 10.0). The interesting test mixes would be those that use subquery materialization (need uncorrelated IN subqueries), and non-SELECT statements.