diff --git a/mysql-test/main/delete_multi_order_by.result b/mysql-test/main/delete_multi_order_by.result index 656090040ef5d..eddc3f55f2538 100644 --- a/mysql-test/main/delete_multi_order_by.result +++ b/mysql-test/main/delete_multi_order_by.result @@ -423,5 +423,14 @@ COUNT(*) 0 DROP TABLE t1; # +# MDEV-40573 Assertion `del_table == table_being_deleted' failed in +# multi_delete::send_data on DELETE w/ index hint + window function +# +CREATE TABLE t1 (c INT PRIMARY KEY); +INSERT INTO t1 (c) VALUES (1),(2),(3),(4); +DELETE FROM t1 USE KEY() WHERE 0 +ORDER BY PERCENTILE_CONT(COUNT(*)) WITHIN GROUP(ORDER BY c) OVER(); +DROP TABLE t1; +# # End 11.8 tests # diff --git a/mysql-test/main/delete_multi_order_by.test b/mysql-test/main/delete_multi_order_by.test index c2c2b28155353..a57b6b9144c2f 100644 --- a/mysql-test/main/delete_multi_order_by.test +++ b/mysql-test/main/delete_multi_order_by.test @@ -228,6 +228,16 @@ DELETE FROM a3,a1 USING t1 AS a1 JOIN t1 AS a2 JOIN t1 AS a3; SELECT COUNT(*) from t1; DROP TABLE t1; +--echo # +--echo # MDEV-40573 Assertion `del_table == table_being_deleted' failed in +--echo # multi_delete::send_data on DELETE w/ index hint + window function +--echo # +CREATE TABLE t1 (c INT PRIMARY KEY); +INSERT INTO t1 (c) VALUES (1),(2),(3),(4); +DELETE FROM t1 USE KEY() WHERE 0 + ORDER BY PERCENTILE_CONT(COUNT(*)) WITHIN GROUP(ORDER BY c) OVER(); +DROP TABLE t1; + --echo # --echo # End 11.8 tests --echo # diff --git a/sql/sql_class.h b/sql/sql_class.h index 5ca2eac6f4403..788f88023e0f7 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -7717,6 +7717,7 @@ class multi_delete :public select_result_interceptor /* True if at least one table we delete from is not transactional */ bool normal_tables; bool delete_while_scanning; + bool tables_initialized; /* error handling (rollback and binlogging) can happen in send_eof() so that afterward abort_result_set() needs to find out that. diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 37495077b74f5..dbb9e31d689f1 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -1165,6 +1165,7 @@ multi_delete::multi_delete(THD *thd_arg, do_delete(0), transactional_tables(0), normal_tables(0), + tables_initialized(false), error_handled(0) { tmp_tables = thd->calloc