This script:
DROP TABLE IF EXISTS t1,t2,t3;
CREATE TABLE t1 (a INT );
CREATE TABLE t2 (a INT );
CREATE TABLE t3 (a INT );
INSERT INTO t1 VALUES (1),(2),(3);
INSERT INTO t2 VALUES (1),(2),(3);
INSERT INTO t3 VALUES (1),(2),(3);
EXPLAIN SELECT * FROM ( WITH a AS ( SELECT * FROM t1) (t2 NATURAL JOIN t3));
returns
+------+-------------+-------+------+---------------+------+---------+------+------+-------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------------------------------------------+
| 1 | PRIMARY | t2 | ALL | NULL | NULL | NULL | NULL | 3 | |
| 1 | PRIMARY | t3 | ALL | NULL | NULL | NULL | NULL | 3 | Using where; Using join buffer (flat, BNL join) |
| 2 | SUBQUERY | t1 | ALL | NULL | NULL | NULL | NULL | 3 | |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------------------------------------------+
This looks wrong. The table "t1" does not affect the result and should probably be optimized away.
relates to
MDEV-10057
Crash with EXPLAIN + WITH + constant query
Closed
Alexander Barkov
made changes -
2016-05-12 10:40
Field
Original Value
New Value
Assignee
Igor Babaev
[ igor
]
Alexander Barkov
made changes -
2016-05-12 10:41
Description
This script:
{code:sql}
DROP TABLE IF EXISTS t1,t2,t3;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
CREATE TABLE t3 (a INT);
INSERT INTO t1 VALUES (1),(2),(3);
INSERT INTO t2 VALUES (1),(2),(3);
INSERT INTO t3 VALUES (1),(2),(3);
EXPLAIN SELECT * FROM (WITH a AS (SELECT * FROM t1) (t2 NATURAL JOIN t3));
{code}
returns
{noformat}
+------+-------------+-------+------+---------------+------+---------+------+------+-------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------------------------------------------+
| 1 | PRIMARY | t2 | ALL | NULL | NULL | NULL | NULL | 3 | |
| 1 | PRIMARY | t3 | ALL | NULL | NULL | NULL | NULL | 3 | Using where; Using join buffer (flat, BNL join) |
| 2 | SUBQUERY | t1 | ALL | NULL | NULL | NULL | NULL | 3 | |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------------------------------------------+
{noforma}
This looks wrong. The table "t1" does not affect the result and should probably be optimized away.
This script:
{code:sql}
DROP TABLE IF EXISTS t1,t2,t3;
CREATE TABLE t1 (a INT);
CREATE TABLE t2 (a INT);
CREATE TABLE t3 (a INT);
INSERT INTO t1 VALUES (1),(2),(3);
INSERT INTO t2 VALUES (1),(2),(3);
INSERT INTO t3 VALUES (1),(2),(3);
EXPLAIN SELECT * FROM (WITH a AS (SELECT * FROM t1) (t2 NATURAL JOIN t3));
{code}
returns
{noformat}
+------+-------------+-------+------+---------------+------+---------+------+------+-------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------------------------------------------+
| 1 | PRIMARY | t2 | ALL | NULL | NULL | NULL | NULL | 3 | |
| 1 | PRIMARY | t3 | ALL | NULL | NULL | NULL | NULL | 3 | Using where; Using join buffer (flat, BNL join) |
| 2 | SUBQUERY | t1 | ALL | NULL | NULL | NULL | NULL | 3 | |
+------+-------------+-------+------+---------------+------+---------+------+------+-------------------------------------------------+
{noformat}
This looks wrong. The table "t1" does not affect the result and should probably be optimized away.
Elena Stepanova
made changes -
2016-05-14 09:30
Component/s
Optimizer - CTE
[ 13513
]
Component/s
Optimizer
[ 10200
]
Sergei Petrunia
made changes -
2016-09-04 10:44
Fix Version/s
10.2.2
[ 22013
]
Fix Version/s
10.2
[ 14601
]
Resolution
Fixed
[ 1
]
Status
Open
[ 1
]
Closed
[ 6
]
Alexander Barkov
made changes -
2016-09-07 06:27
Resolution
Fixed
[ 1
]
Status
Closed
[ 6
]
Stalled
[ 10000
]
Sergei Petrunia
made changes -
2016-09-07 09:31
Resolution
Fixed
[ 1
]
Status
Stalled
[ 10000
]
Closed
[ 6
]
Sergei Golubchik
made changes -
2021-12-06 21:42
Workflow
MariaDB v3
[ 75651
]
MariaDB v4
[ 150421
]
{"report":{"fcp":889,"ttfb":269.19999998807907,"pageVisibility":"visible","entityId":56713,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"6011995d-c5a5-4248-a3f6-dc8f1f7d8572","navigationType":0,"readyForUser":963.3999999761581,"redirectCount":0,"resourceLoadedEnd":990.3999999761581,"resourceLoadedStart":274.19999998807907,"resourceTiming":[{"duration":125.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":274.19999998807907,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":274.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":399.69999998807907,"responseStart":0,"secureConnectionStart":0},{"duration":125.5,"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":274.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":274.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":400,"responseStart":0,"secureConnectionStart":0},{"duration":134,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":274.69999998807907,"connectEnd":274.69999998807907,"connectStart":274.69999998807907,"domainLookupEnd":274.69999998807907,"domainLookupStart":274.69999998807907,"fetchStart":274.69999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":274.69999998807907,"responseEnd":408.69999998807907,"responseStart":408.69999998807907,"secureConnectionStart":274.69999998807907},{"duration":187.4000000357628,"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":274.89999997615814,"connectEnd":274.89999997615814,"connectStart":274.89999997615814,"domainLookupEnd":274.89999997615814,"domainLookupStart":274.89999997615814,"fetchStart":274.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":274.89999997615814,"responseEnd":462.30000001192093,"responseStart":462.30000001192093,"secureConnectionStart":274.89999997615814},{"duration":190.5999999642372,"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":275,"connectEnd":275,"connectStart":275,"domainLookupEnd":275,"domainLookupStart":275,"fetchStart":275,"redirectEnd":0,"redirectStart":0,"requestStart":275,"responseEnd":465.5999999642372,"responseStart":465.5999999642372,"secureConnectionStart":275},{"duration":190.80000001192093,"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":275.19999998807907,"connectEnd":275.19999998807907,"connectStart":275.19999998807907,"domainLookupEnd":275.19999998807907,"domainLookupStart":275.19999998807907,"fetchStart":275.19999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":275.19999998807907,"responseEnd":466,"responseStart":466,"secureConnectionStart":275.19999998807907},{"duration":190.9000000357628,"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":275.39999997615814,"connectEnd":275.39999997615814,"connectStart":275.39999997615814,"domainLookupEnd":275.39999997615814,"domainLookupStart":275.39999997615814,"fetchStart":275.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":275.39999997615814,"responseEnd":466.30000001192093,"responseStart":466.30000001192093,"secureConnectionStart":275.39999997615814},{"duration":270.89999997615814,"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":275.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":275.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":546.3999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":191.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":275.69999998807907,"connectEnd":275.69999998807907,"connectStart":275.69999998807907,"domainLookupEnd":275.69999998807907,"domainLookupStart":275.69999998807907,"fetchStart":275.69999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":275.69999998807907,"responseEnd":466.80000001192093,"responseStart":466.80000001192093,"secureConnectionStart":275.69999998807907},{"duration":270.7999999523163,"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":275.80000001192093,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":275.80000001192093,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":546.5999999642372,"responseStart":0,"secureConnectionStart":0},{"duration":191.19999998807907,"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":276,"connectEnd":276,"connectStart":276,"domainLookupEnd":276,"domainLookupStart":276,"fetchStart":276,"redirectEnd":0,"redirectStart":0,"requestStart":276,"responseEnd":467.19999998807907,"responseStart":467.19999998807907,"secureConnectionStart":276},{"duration":358.4000000357628,"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":281.5999999642372,"connectEnd":281.5999999642372,"connectStart":281.5999999642372,"domainLookupEnd":281.5999999642372,"domainLookupStart":281.5999999642372,"fetchStart":281.5999999642372,"redirectEnd":0,"redirectStart":0,"requestStart":281.5999999642372,"responseEnd":640,"responseStart":640,"secureConnectionStart":281.5999999642372},{"duration":637.5,"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":282.0999999642372,"connectEnd":282.0999999642372,"connectStart":282.0999999642372,"domainLookupEnd":282.0999999642372,"domainLookupStart":282.0999999642372,"fetchStart":282.0999999642372,"redirectEnd":0,"redirectStart":0,"requestStart":282.0999999642372,"responseEnd":919.5999999642372,"responseStart":919.5999999642372,"secureConnectionStart":282.0999999642372},{"duration":94.90000003576279,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":572.3999999761581,"connectEnd":572.3999999761581,"connectStart":572.3999999761581,"domainLookupEnd":572.3999999761581,"domainLookupStart":572.3999999761581,"fetchStart":572.3999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":572.3999999761581,"responseEnd":667.3000000119209,"responseStart":667.3000000119209,"secureConnectionStart":572.3999999761581},{"duration":180.30000001192093,"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":810.0999999642372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":810.0999999642372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":990.3999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":224.30000001192093,"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":811,"connectEnd":811,"connectStart":811,"domainLookupEnd":811,"domainLookupStart":811,"fetchStart":811,"redirectEnd":0,"redirectStart":0,"requestStart":811,"responseEnd":1035.300000011921,"responseStart":1035.300000011921,"secureConnectionStart":811},{"duration":229.39999997615814,"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":811.3000000119209,"connectEnd":811.3000000119209,"connectStart":811.3000000119209,"domainLookupEnd":811.3000000119209,"domainLookupStart":811.3000000119209,"fetchStart":811.3000000119209,"redirectEnd":0,"redirectStart":0,"requestStart":811.3000000119209,"responseEnd":1040.699999988079,"responseStart":1040.699999988079,"secureConnectionStart":811.3000000119209},{"duration":202.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":883.3000000119209,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":883.3000000119209,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1085.800000011921,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":66,"responseStart":269,"responseEnd":280,"domLoading":273,"domInteractive":1031,"domContentLoadedEventStart":1031,"domContentLoadedEventEnd":1076,"domComplete":1400,"loadEventStart":1400,"loadEventEnd":1401,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1002.8999999761581},{"name":"bigPipe.sidebar-id.end","time":1003.6999999880791},{"name":"bigPipe.activity-panel-pipe-id.start","time":1003.8999999761581},{"name":"bigPipe.activity-panel-pipe-id.end","time":1008},{"name":"activityTabFullyLoaded","time":1105.3999999761581}],"measures":[],"correlationId":"6b11ca7d6e1fac","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":140,"dbReadsTimeInMs":23,"dbConnsTimeInMs":32,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
By the way, this syntax is not standard:
<with clause> cannot be followed by a <parenthesized joined table>.
It can be followed by <query expression> only.
The correct standard syntax is:
And EXPLAIN for this standard query crashes. See
MDEV-10057.