summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/include/handler.inc53
-rw-r--r--mysql-test/r/handler_innodb.result25
-rw-r--r--mysql-test/r/handler_myisam.result25
-rw-r--r--sql/sql_handler.cc4
4 files changed, 107 insertions, 0 deletions
diff --git a/mysql-test/include/handler.inc b/mysql-test/include/handler.inc
index 2de514f27bb..0031cb68647 100644
--- a/mysql-test/include/handler.inc
+++ b/mysql-test/include/handler.inc
@@ -1704,3 +1704,56 @@ unlock tables;
--echo # already released by commit.
handler t1 close;
drop tables t1, t2;
+
+
+--echo #
+--echo # Bug#51355 handler stmt cause assertion in
+--echo # bool MDL_context::try_acquire_lock(MDL_request*)
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+connect(con51355, localhost, root);
+
+--echo # Connection default
+connection default;
+CREATE TABLE t1(id INT, KEY id(id));
+HANDLER t1 OPEN;
+
+--echo # Connection con51355
+connection con51355;
+--echo # Sending:
+--send DROP TABLE t1
+
+--echo # Connection default
+connection default;
+--echo # This I_S query will cause the handler table to be closed and
+--echo # the metadata lock to be released. This will allow DROP TABLE
+--echo # to proceed. Waiting for the table to be removed.
+let $wait_condition=
+ SELECT COUNT(*) = 0 FROM information_schema.tables WHERE table_name = "t1";
+--source include/wait_condition.inc
+
+--echo # Connection con51355
+connection con51355;
+--echo # Reaping: DROP TABLE t1
+--reap
+
+--echo # Connection default
+connection default;
+--error ER_NO_SUCH_TABLE
+HANDLER t1 READ id NEXT;
+# This caused an assertion
+--error ER_NO_SUCH_TABLE
+HANDLER t1 READ id NEXT;
+
+HANDLER t1 CLOSE;
+--echo # Connection con51355
+connection con51355;
+disconnect con51355;
+--source include/wait_until_disconnected.inc
+--echo # Connection default
+connection default;
+
diff --git a/mysql-test/r/handler_innodb.result b/mysql-test/r/handler_innodb.result
index 58083194b83..08d2fc58e8a 100644
--- a/mysql-test/r/handler_innodb.result
+++ b/mysql-test/r/handler_innodb.result
@@ -1685,3 +1685,28 @@ unlock tables;
# already released by commit.
handler t1 close;
drop tables t1, t2;
+#
+# Bug#51355 handler stmt cause assertion in
+# bool MDL_context::try_acquire_lock(MDL_request*)
+#
+DROP TABLE IF EXISTS t1;
+# Connection default
+CREATE TABLE t1(id INT, KEY id(id));
+HANDLER t1 OPEN;
+# Connection con51355
+# Sending:
+DROP TABLE t1;
+# Connection default
+# This I_S query will cause the handler table to be closed and
+# the metadata lock to be released. This will allow DROP TABLE
+# to proceed. Waiting for the table to be removed.
+# Connection con51355
+# Reaping: DROP TABLE t1
+# Connection default
+HANDLER t1 READ id NEXT;
+ERROR 42S02: Table 'test.t1' doesn't exist
+HANDLER t1 READ id NEXT;
+ERROR 42S02: Table 'test.t1' doesn't exist
+HANDLER t1 CLOSE;
+# Connection con51355
+# Connection default
diff --git a/mysql-test/r/handler_myisam.result b/mysql-test/r/handler_myisam.result
index dd199e40574..2625222ec1a 100644
--- a/mysql-test/r/handler_myisam.result
+++ b/mysql-test/r/handler_myisam.result
@@ -1682,6 +1682,31 @@ unlock tables;
handler t1 close;
drop tables t1, t2;
#
+# Bug#51355 handler stmt cause assertion in
+# bool MDL_context::try_acquire_lock(MDL_request*)
+#
+DROP TABLE IF EXISTS t1;
+# Connection default
+CREATE TABLE t1(id INT, KEY id(id));
+HANDLER t1 OPEN;
+# Connection con51355
+# Sending:
+DROP TABLE t1;
+# Connection default
+# This I_S query will cause the handler table to be closed and
+# the metadata lock to be released. This will allow DROP TABLE
+# to proceed. Waiting for the table to be removed.
+# Connection con51355
+# Reaping: DROP TABLE t1
+# Connection default
+HANDLER t1 READ id NEXT;
+ERROR 42S02: Table 'test.t1' doesn't exist
+HANDLER t1 READ id NEXT;
+ERROR 42S02: Table 'test.t1' doesn't exist
+HANDLER t1 CLOSE;
+# Connection con51355
+# Connection default
+#
# BUG #46456: HANDLER OPEN + TRUNCATE + DROP (temporary) TABLE, crash
#
CREATE TABLE t1 AS SELECT 1 AS f1;
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index 4a69b46ddb7..3afeb4164bd 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -311,7 +311,11 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, bool reopen)
if (!reopen)
my_hash_delete(&thd->handler_tables_hash, (uchar*) hash_tables);
else
+ {
hash_tables->table= NULL;
+ /* Safety, cleanup the pointer to satisfy MDL assertions. */
+ hash_tables->mdl_request.ticket= NULL;
+ }
DBUG_PRINT("exit",("ERROR"));
DBUG_RETURN(TRUE);
}