You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug#37560280 Incorrect behavior with EXPLAIN and subqueries
EXPLAIN could execute a stored function in a subquery when the subquery created a derived table, e.g.: EXPLAIN SELECT * FROM (SELECT f()) AS a; This issue was caused by Table_ref::materializable_is_const(), which incorrectly treated a function call as a constant expression. Now, we ensure that a derived table subquery containing a stored function call is not considered constant. Change-Id: Id73d567b3617da1523996e8ee0ed73b4879451ad (cherry picked from commit 2830b52f5515af4f7e9330492593446b215b004a)
1 SIMPLE t2p0,p1,p2 eq_refPRIMARY PRIMARY 4 const # 100.00Using where
5034
5034
Warnings:
5035
-
Note 1003 /* select#1 */ select '1' AS `a`,'1' AS `b` from `test`.`t2` where true
5035
+
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`a` = <cache>(`sf_a_from_t1b_d`('1')))
5036
5036
FLUSH STATUS;
5037
5037
START TRANSACTION;
5038
5038
SELECT * FROM t2 WHERE a = sf_a_from_t1b_d('1');
@@ -5086,9 +5086,9 @@ Handler_read_next 12
5086
5086
UNLOCK TABLES;
5087
5087
EXPLAIN SELECT * FROM t2 WHERE a = 7 + sf_a_from_t1b_d('1');
5088
5088
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE t2p0,p1,p2eq_refPRIMARY PRIMARY 4 const # 100.00Using where
5090
5090
Warnings:
5091
-
Note 1003 /* select#1 */ select '8' AS `a`,'8' AS `b` from `test`.`t2` where true
5091
+
Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`a` = <cache>((7 + `sf_a_from_t1b_d`('1'))))
5092
5092
FLUSH STATUS;
5093
5093
START TRANSACTION;
5094
5094
SELECT * FROM t2 WHERE a = 7 + sf_a_from_t1b_d('1');
@@ -5138,9 +5138,9 @@ Handler_read_next 7
5138
5138
UNLOCK TABLES;
5139
5139
EXPLAIN SELECT * FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
5140
5140
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
5141
-
1 SIMPLENULL NULL NULL NULL NULL NULL NULL#NULL Impossible WHERE
Note 1003 /* select#1 */ select (`sf_add_1`(`test`.`t2`.`a`) - 1) AS `sf_add_1(a) - 1`,`sf_add_hello`(`test`.`t2`.`b`) AS `sf_add_hello(b)` from `test`.`t2` where false
5435
+
Note 1003 /* select#1 */ select (`sf_add_1`('2') - 1) AS `sf_add_1(a) - 1`,`sf_add_hello`('2') AS `sf_add_hello(b)` from `test`.`t2` where ((2 = `sf_a_from_t1b_d`('1')))
5436
5436
FLUSH STATUS;
5437
5437
START TRANSACTION;
5438
5438
SELECT sf_add_1(a) - 1, sf_add_hello(b) FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -5652,7 +5652,7 @@ ROLLBACK;
5652
5652
UNLOCK TABLES;
5653
5653
EXPLAIN UPDATE t2 SET b = CONCAT('+', b) WHERE a = sf_a_from_t1b_d('1');
5654
5654
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
5655
-
1 UPDATE t2p1 range PRIMARYPRIMARY 4const# 100.00 Using where
5655
+
1 UPDATE t2p0,p1,p2 index NULLPRIMARY 4NULL# 100.00 Using where
5656
5656
Warnings:
5657
5657
Note 1003 update `test`.`t2` set `test`.`t2`.`b` = concat('+',`test`.`t2`.`b`) where (`test`.`t2`.`a` = `sf_a_from_t1b_d`('1'))
5658
5658
FLUSH STATUS;
@@ -5734,7 +5734,7 @@ ROLLBACK;
5734
5734
UNLOCK TABLES;
5735
5735
EXPLAIN UPDATE t2 SET b = CONCAT('+', b) WHERE a = 7 + sf_a_from_t1b_d('1');
5736
5736
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
5737
-
1 UPDATE t2 p2range PRIMARYPRIMARY 4const# 100.00 Using where
5737
+
1 UPDATE t2p0,p1,p2index NULLPRIMARY 4NULL# 100.00 Using where
5738
5738
Warnings:
5739
5739
Note 1003 update `test`.`t2` set `test`.`t2`.`b` = concat('+',`test`.`t2`.`b`) where (`test`.`t2`.`a` = (7 + `sf_a_from_t1b_d`('1')))
5740
5740
FLUSH STATUS;
@@ -5808,9 +5808,9 @@ ROLLBACK;
5808
5808
UNLOCK TABLES;
5809
5809
EXPLAIN UPDATE t2 SET b = CONCAT('+', b) WHERE a = sf_a_from_t1b_d('1') AND a = 2;
5810
5810
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
5811
-
1 UPDATENULL NULL NULL NULL NULL NULL NULL#NULL Impossible WHERE
5811
+
1 UPDATEt2 p2 range PRIMARY PRIMARY 4 const#100.00 Using where
5812
5812
Warnings:
5813
-
Note 1003 update `test`.`t2` set `test`.`t2`.`b` = concat('+',`test`.`t2`.`b`) where ()
5813
+
Note 1003 update `test`.`t2` set `test`.`t2`.`b` = concat('+',`test`.`t2`.`b`) where ((`test`.`t2`.`a` = 2) and (2 = `sf_a_from_t1b_d`('1')))
5814
5814
FLUSH STATUS;
5815
5815
START TRANSACTION;
5816
5816
UPDATE t2 SET b = CONCAT('+', b) WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -6064,7 +6064,7 @@ ROLLBACK;
6064
6064
UNLOCK TABLES;
6065
6065
EXPLAIN UPDATE t2 SET b = sf_add_hello(b) WHERE a = sf_a_from_t1b_d('1');
6066
6066
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
6067
-
1 UPDATE t2p1 range PRIMARYPRIMARY 4const# 100.00 Using where
6067
+
1 UPDATE t2p0,p1,p2 index NULLPRIMARY 4NULL# 100.00 Using where
6068
6068
Warnings:
6069
6069
Note 1003 update `test`.`t2` set `test`.`t2`.`b` = `sf_add_hello`(`test`.`t2`.`b`) where (`test`.`t2`.`a` = `sf_a_from_t1b_d`('1'))
6070
6070
FLUSH STATUS;
@@ -6146,7 +6146,7 @@ ROLLBACK;
6146
6146
UNLOCK TABLES;
6147
6147
EXPLAIN UPDATE t2 SET b = sf_add_hello(b) WHERE a = 7 + sf_a_from_t1b_d('1');
6148
6148
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
6149
-
1 UPDATE t2 p2range PRIMARYPRIMARY 4const# 100.00 Using where
6149
+
1 UPDATE t2p0,p1,p2index NULLPRIMARY 4NULL# 100.00 Using where
6150
6150
Warnings:
6151
6151
Note 1003 update `test`.`t2` set `test`.`t2`.`b` = `sf_add_hello`(`test`.`t2`.`b`) where (`test`.`t2`.`a` = (7 + `sf_a_from_t1b_d`('1')))
6152
6152
FLUSH STATUS;
@@ -6220,9 +6220,9 @@ ROLLBACK;
6220
6220
UNLOCK TABLES;
6221
6221
EXPLAIN UPDATE t2 SET b = sf_add_hello(b) WHERE a = sf_a_from_t1b_d('1') AND a = 2;
6222
6222
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
6223
-
1 UPDATENULL NULL NULL NULL NULL NULL NULL#NULL Impossible WHERE
6223
+
1 UPDATEt2 p2 range PRIMARY PRIMARY 4 const#100.00 Using where
6224
6224
Warnings:
6225
-
Note 1003 update `test`.`t2` set `test`.`t2`.`b` = `sf_add_hello`(`test`.`t2`.`b`) where ()
6225
+
Note 1003 update `test`.`t2` set `test`.`t2`.`b` = `sf_add_hello`(`test`.`t2`.`b`) where ((`test`.`t2`.`a` = 2) and (2 = `sf_a_from_t1b_d`('1')))
6226
6226
FLUSH STATUS;
6227
6227
START TRANSACTION;
6228
6228
UPDATE t2 SET b = sf_add_hello(b) WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -6482,7 +6482,7 @@ ROLLBACK;
6482
6482
UNLOCK TABLES;
6483
6483
EXPLAIN UPDATE t2 SET a = sf_add_1(a) + 4 WHERE a = sf_a_from_t1b_d('1');
6484
6484
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
6485
-
1 UPDATE t2p1 range PRIMARYPRIMARY 4const# 100.00 Using where
6485
+
1 UPDATE t2p0,p1,p2 index NULLPRIMARY 4NULL# 100.00 Using where; Using temporary
6486
6486
Warnings:
6487
6487
Note 1003 update `test`.`t2` set `test`.`t2`.`a` = (`sf_add_1`(`test`.`t2`.`a`) + 4) where (`test`.`t2`.`a` = `sf_a_from_t1b_d`('1'))
6488
6488
FLUSH STATUS;
@@ -6568,7 +6568,7 @@ ROLLBACK;
6568
6568
UNLOCK TABLES;
6569
6569
EXPLAIN UPDATE t2 SET a = sf_add_1(a) + 4 WHERE a = 7 + sf_a_from_t1b_d('1');
6570
6570
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
6571
-
1 UPDATE t2 p2range PRIMARYPRIMARY 4const# 100.00 Using where
6571
+
1 UPDATE t2p0,p1,p2index NULLPRIMARY 4NULL# 100.00 Using where; Using temporary
6572
6572
Warnings:
6573
6573
Note 1003 update `test`.`t2` set `test`.`t2`.`a` = (`sf_add_1`(`test`.`t2`.`a`) + 4) where (`test`.`t2`.`a` = (7 + `sf_a_from_t1b_d`('1')))
6574
6574
FLUSH STATUS;
@@ -6644,9 +6644,9 @@ ROLLBACK;
6644
6644
UNLOCK TABLES;
6645
6645
EXPLAIN UPDATE t2 SET a = sf_add_1(a) + 4 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
6646
6646
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
6647
-
1 UPDATENULL NULL NULL NULL NULL NULL NULL#NULL Impossible WHERE
6647
+
1 UPDATEt2 p2 range PRIMARY PRIMARY 4 const#100.00 Using where
6648
6648
Warnings:
6649
-
Note 1003 update `test`.`t2` set `test`.`t2`.`a` = (`sf_add_1`(`test`.`t2`.`a`) + 4) where ()
6649
+
Note 1003 update `test`.`t2` set `test`.`t2`.`a` = (`sf_add_1`(`test`.`t2`.`a`) + 4) where ((`test`.`t2`.`a` = 2) and (2 = `sf_a_from_t1b_d`('1')))
6650
6650
FLUSH STATUS;
6651
6651
START TRANSACTION;
6652
6652
UPDATE t2 SET a = sf_add_1(a) + 4 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
@@ -6899,7 +6899,7 @@ ROLLBACK;
6899
6899
UNLOCK TABLES;
6900
6900
EXPLAIN DELETE FROM t2 WHERE a = sf_a_from_t1b_d('1');
6901
6901
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
6902
-
1 DELETE t2p1 range PRIMARY PRIMARY 4 const# 100.00 Using where
6902
+
1 DELETE t2p0,p1,p2 ALL NULL NULL NULL NULL# 100.00 Using where
6903
6903
Warnings:
6904
6904
Note 1003 delete from `test`.`t2` where (`test`.`t2`.`a` = `sf_a_from_t1b_d`('1'))
6905
6905
FLUSH STATUS;
@@ -6977,7 +6977,7 @@ ROLLBACK;
6977
6977
UNLOCK TABLES;
6978
6978
EXPLAIN DELETE FROM t2 WHERE a = 7 + sf_a_from_t1b_d('1');
6979
6979
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
6980
-
1 DELETE t2 p2range PRIMARY PRIMARY 4 const# 100.00 Using where
6980
+
1 DELETE t2p0,p1,p2ALL NULL NULL NULL NULL# 100.00 Using where
6981
6981
Warnings:
6982
6982
Note 1003 delete from `test`.`t2` where (`test`.`t2`.`a` = (7 + `sf_a_from_t1b_d`('1')))
6983
6983
FLUSH STATUS;
@@ -7049,9 +7049,9 @@ ROLLBACK;
7049
7049
UNLOCK TABLES;
7050
7050
EXPLAIN DELETE FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
7051
7051
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
7052
-
1 DELETENULL NULL NULL NULL NULL NULL NULL#NULL Impossible WHERE
7052
+
1 DELETEt2 p2 range PRIMARY PRIMARY 4 const#100.00 Using where
7053
7053
Warnings:
7054
-
Note 1003 delete from `test`.`t2` where ()
7054
+
Note 1003 delete from `test`.`t2` where ((`test`.`t2`.`a` = 2) and (2 = `sf_a_from_t1b_d`('1')))
7055
7055
FLUSH STATUS;
7056
7056
START TRANSACTION;
7057
7057
DELETE FROM t2 WHERE a = sf_a_from_t1b_d('1') AND a = 2;
0 commit comments