diff options
-rw-r--r-- | mysql-test/r/ps.result | 18 | ||||
-rw-r--r-- | mysql-test/t/ps.test | 14 | ||||
-rw-r--r-- | sql/sql_base.cc | 17 | ||||
-rw-r--r-- | sql/sql_base.h | 2 | ||||
-rw-r--r-- | sql/sql_delete.cc | 2 | ||||
-rw-r--r-- | sql/sql_update.cc | 2 |
6 files changed, 55 insertions, 0 deletions
diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 4ee72f10785..f1f779ef03f 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -5456,5 +5456,23 @@ Note 1003 select (select 1 from `test`.`t2` where 0) AS `(SELECT 1 FROM t2 WHERE DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; # +# MDEV-25576: The statement EXPLAIN running as regular statement and +# as prepared statement produces different results for +# UPDATE with subquery +# +CREATE TABLE t1 (c1 INT KEY) ENGINE=MyISAM; +CREATE TABLE t2 (c2 INT) ENGINE=MyISAM; +CREATE TABLE t3 (c3 INT) ENGINE=MyISAM; +EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 ON a12.c1 = a11.c1 ) d1 ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +PREPARE stmt FROM "EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 ON a12.c1 = a11.c1 ) d1 )"; +EXECUTE stmt; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 0 100.00 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +DEALLOCATE PREPARE stmt; +DROP TABLE t1, t2, t3; # End of 10.2 tests # diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 5b86f82a9cb..2e7b43ad748 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -4946,6 +4946,20 @@ SHOW WARNINGS; DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; + +--echo # +--echo # MDEV-25576: The statement EXPLAIN running as regular statement and +--echo # as prepared statement produces different results for +--echo # UPDATE with subquery --echo # +CREATE TABLE t1 (c1 INT KEY) ENGINE=MyISAM; +CREATE TABLE t2 (c2 INT) ENGINE=MyISAM; +CREATE TABLE t3 (c3 INT) ENGINE=MyISAM; +EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 ON a12.c1 = a11.c1 ) d1 ); +PREPARE stmt FROM "EXPLAIN EXTENDED UPDATE t3 SET c3 = ( SELECT COUNT(d1.c1) FROM ( SELECT a11.c1 FROM t1 AS a11 STRAIGHT_JOIN t2 AS a21 ON a21.c2 = a11.c1 JOIN t1 AS a12 ON a12.c1 = a11.c1 ) d1 )"; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; +DROP TABLE t1, t2, t3; + --echo # End of 10.2 tests --echo # diff --git a/sql/sql_base.cc b/sql/sql_base.cc index c9a34221544..11f4cb9890b 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -8794,6 +8794,23 @@ int dynamic_column_error_message(enum_dyncol_func_result rc) return rc; } + +/** + Turn on the SELECT_DESCRIBE flag for the primary SELECT_LEX of the statement + being processed in case the statement is EXPLAIN UPDATE/DELETE. + + @param lex current LEX +*/ + +void promote_select_describe_flag_if_needed(LEX *lex) +{ + if (lex->describe) + { + lex->select_lex.options |= SELECT_DESCRIBE; + } +} + + /** @} (end of group Data_Dictionary) */ diff --git a/sql/sql_base.h b/sql/sql_base.h index b67341bcbda..5674e8378c5 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -516,6 +516,8 @@ bool extend_table_list(THD *thd, TABLE_LIST *tables, Prelocking_strategy *prelocking_strategy, bool has_prelocking_list); +void promote_select_describe_flag_if_needed(LEX *lex); + /** A context of open_tables() function, used to recover from a failed open_table() or open_routine() attempt. diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index e2bf2d727b1..a26e15431a6 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -274,6 +274,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, query_plan.table= table; query_plan.updating_a_view= MY_TEST(table_list->view); + promote_select_describe_flag_if_needed(thd->lex); + if (mysql_prepare_delete(thd, table_list, select_lex->with_wild, select_lex->item_list, &conds)) DBUG_RETURN(TRUE); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index ec27ccda778..b7ef7c2a0db 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -342,6 +342,8 @@ int mysql_update(THD *thd, want_privilege= (table_list->view ? UPDATE_ACL : table_list->grant.want_privilege); #endif + promote_select_describe_flag_if_needed(thd->lex); + if (mysql_prepare_update(thd, table_list, &conds, order_num, order)) DBUG_RETURN(1); |