If the where condition of a query contains a non-correlated, non-expensive subquery then
then different executions of the prepared statement made for the query may use
different execution plans.
The following test case demonstrates this.
create table t1 (id int, c varchar(3), key idx(c))engine=myisam;
|
insert into t1 values (3,'bar'), (1,'xxx'), (2,'foo'), (5,'yyy');
|
|
prepare stmt1 from
|
"explain extended
|
select * from t1 where (1, 2) in ( select 3, 4 ) or c = 'foo'";
|
execute stmt1;
|
execute stmt1;
|
deallocate prepare stmt1;
|
|
prepare stmt2 from
|
"explain extended
|
select * from t1 where (1, 2) in ( select 3, 4 )";
|
execute stmt2;
|
execute stmt2;
|
deallocate prepare stmt2;
|
|
drop table t1;
|
Here for the first and the second executions of the prepared statement stmt1 we have:
MariaDB [test]> execute stmt1;
|
+------+-------------+-------+------+---------------+------+---------+-------+------+----------+-----------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+------+---------------+------+---------+-------+------+----------+-----------------------+
|
| 1 | PRIMARY | t1 | ref | idx | idx | 6 | const | 1 | 100.00 | Using index condition |
|
| 2 | SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
|
+------+-------------+-------+------+---------------+------+---------+-------+------+----------+-----------------------+
|
|
MariaDB [test]> execute stmt1;
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------+
|
| 1 | PRIMARY | t1 | ALL | idx | NULL | NULL | NULL | 4 | 100.00 | Using where |
|
| 2 | SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------+
|
While for the first and the second executions of the prepared statement stmt2 the plans are
as follows:
ariaDB [test]> execute stmt2;
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------+
|
| 1 | PRIMARY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE |
|
| 2 | SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------+
|
|
MariaDB [test]> execute stmt2;
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------+
|
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 4 | 100.00 | |
|
| 2 | SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
|
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------+
|
{"report":{"fcp":940,"ttfb":325.40000000596046,"pageVisibility":"visible","entityId":59903,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"b9f5014f-524b-4502-8c8d-22e50103b2ff","navigationType":0,"readyForUser":1017.0999999940395,"redirectCount":0,"resourceLoadedEnd":1062.4000000059605,"resourceLoadedStart":330.59999999403954,"resourceTiming":[{"duration":54.400000005960464,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":330.59999999403954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":330.59999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":385,"responseStart":0,"secureConnectionStart":0},{"duration":55.30000001192093,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":331,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":331,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":386.30000001192093,"responseStart":0,"secureConnectionStart":0},{"duration":111.7000000178814,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":331.09999999403954,"connectEnd":331.09999999403954,"connectStart":331.09999999403954,"domainLookupEnd":331.09999999403954,"domainLookupStart":331.09999999403954,"fetchStart":331.09999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":331.09999999403954,"responseEnd":442.80000001192093,"responseStart":442.80000001192093,"secureConnectionStart":331.09999999403954},{"duration":189.59999999403954,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":331.2000000178814,"connectEnd":331.2000000178814,"connectStart":331.2000000178814,"domainLookupEnd":331.2000000178814,"domainLookupStart":331.2000000178814,"fetchStart":331.2000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":331.2000000178814,"responseEnd":520.8000000119209,"responseStart":520.8000000119209,"secureConnectionStart":331.2000000178814},{"duration":193,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":331.40000000596046,"connectEnd":331.40000000596046,"connectStart":331.40000000596046,"domainLookupEnd":331.40000000596046,"domainLookupStart":331.40000000596046,"fetchStart":331.40000000596046,"redirectEnd":0,"redirectStart":0,"requestStart":331.40000000596046,"responseEnd":524.4000000059605,"responseStart":524.4000000059605,"secureConnectionStart":331.40000000596046},{"duration":193.30000001192093,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":331.59999999403954,"connectEnd":331.59999999403954,"connectStart":331.59999999403954,"domainLookupEnd":331.59999999403954,"domainLookupStart":331.59999999403954,"fetchStart":331.59999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":331.59999999403954,"responseEnd":524.9000000059605,"responseStart":524.9000000059605,"secureConnectionStart":331.59999999403954},{"duration":193.7999999821186,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":331.80000001192093,"connectEnd":331.80000001192093,"connectStart":331.80000001192093,"domainLookupEnd":331.80000001192093,"domainLookupStart":331.80000001192093,"fetchStart":331.80000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":331.80000001192093,"responseEnd":525.5999999940395,"responseStart":525.5999999940395,"secureConnectionStart":331.80000001192093},{"duration":250.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":332,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":332,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":582.5,"responseStart":0,"secureConnectionStart":0},{"duration":194.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":332.09999999403954,"connectEnd":332.09999999403954,"connectStart":332.09999999403954,"domainLookupEnd":332.09999999403954,"domainLookupStart":332.09999999403954,"fetchStart":332.09999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":332.09999999403954,"responseEnd":526.2000000178814,"responseStart":526.0999999940395,"secureConnectionStart":332.09999999403954},{"duration":250.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/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":332.2000000178814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":332.2000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":582.7000000178814,"responseStart":0,"secureConnectionStart":0},{"duration":194.30000001192093,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/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":332.5,"connectEnd":332.5,"connectStart":332.5,"domainLookupEnd":332.5,"domainLookupStart":332.5,"fetchStart":332.5,"redirectEnd":0,"redirectStart":0,"requestStart":332.5,"responseEnd":526.8000000119209,"responseStart":526.8000000119209,"secureConnectionStart":332.5},{"duration":446.09999999403954,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":333.2000000178814,"connectEnd":333.2000000178814,"connectStart":333.2000000178814,"domainLookupEnd":333.2000000178814,"domainLookupStart":333.2000000178814,"fetchStart":333.2000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":333.2000000178814,"responseEnd":779.3000000119209,"responseStart":779.3000000119209,"secureConnectionStart":333.2000000178814},{"duration":555.5999999940395,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":333.2000000178814,"connectEnd":333.2000000178814,"connectStart":333.2000000178814,"domainLookupEnd":333.2000000178814,"domainLookupStart":333.2000000178814,"fetchStart":333.2000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":333.2000000178814,"responseEnd":888.8000000119209,"responseStart":888.8000000119209,"secureConnectionStart":333.2000000178814},{"duration":186,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":593.7000000178814,"connectEnd":593.7000000178814,"connectStart":593.7000000178814,"domainLookupEnd":593.7000000178814,"domainLookupStart":593.7000000178814,"fetchStart":593.7000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":593.7000000178814,"responseEnd":779.7000000178814,"responseStart":779.7000000178814,"secureConnectionStart":593.7000000178814},{"duration":50.89999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bv2/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":847.7000000178814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":847.7000000178814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":898.5999999940395,"responseStart":0,"secureConnectionStart":0},{"duration":209.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/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":848.5999999940395,"connectEnd":848.5999999940395,"connectStart":848.5999999940395,"domainLookupEnd":848.5999999940395,"domainLookupStart":848.5999999940395,"fetchStart":848.5999999940395,"redirectEnd":0,"redirectStart":0,"requestStart":848.5999999940395,"responseEnd":1057.7000000178814,"responseStart":1057.7000000178814,"secureConnectionStart":848.5999999940395},{"duration":213.40000000596046,"initiatorType":"script","name":"https://jira.mariadb.org/s/53a43b6764f587426c7bb9a150184c00-CDN/lu2bv2/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":849,"connectEnd":849,"connectStart":849,"domainLookupEnd":849,"domainLookupStart":849,"fetchStart":849,"redirectEnd":0,"redirectStart":0,"requestStart":849,"responseEnd":1062.4000000059605,"responseStart":1062.4000000059605,"secureConnectionStart":849},{"duration":177.2000000178814,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":934.0999999940395,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":934.0999999940395,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1111.300000011921,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":119,"responseStart":325,"responseEnd":327,"domLoading":328,"domInteractive":1071,"domContentLoadedEventStart":1071,"domContentLoadedEventEnd":1111,"domComplete":1712,"loadEventStart":1712,"loadEventEnd":1713,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1052.4000000059605},{"name":"bigPipe.sidebar-id.end","time":1053.0999999940395},{"name":"bigPipe.activity-panel-pipe-id.start","time":1053.2000000178814},{"name":"bigPipe.activity-panel-pipe-id.end","time":1055.7000000178814},{"name":"activityTabFullyLoaded","time":1119.2000000178814}],"measures":[],"correlationId":"826f5ed1ad6a4c","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":109,"dbReadsTimeInMs":11,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}