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 t2 p0,p1,p2 eq_ref PRIMARY PRIMARY 4 const # 100.00 Using 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 t2 p0,p1,p2 eq_ref PRIMARY PRIMARY 4 const # 100.00 Using 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
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 t2 p1 range PRIMARY PRIMARY 4 const # 100.00 Using where
5655
+
1 UPDATE t2 p0,p1,p2 index NULL PRIMARY 4 NULL # 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 p2 range PRIMARY PRIMARY 4 const # 100.00 Using where
5737
+
1 UPDATE t2 p0,p1,p2 index NULL PRIMARY 4 NULL # 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
0 commit comments