From bebe24b03b859d3d01b0bd56356047531a26fac4 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Tue, 26 Dec 2017 14:38:45 +0400 Subject: [PATCH] MDEV-11071 - Assertion `thd->transaction.stmt.is_empty()' failed in Locked_tables_list::unlock_locked_tables Similarly to regular DROP TABLE, don't leave locked tables mode if CREATE OR REPLACE dropped temporary table but failed to cerate new one. The problem is that there's no track of which temporary table was "locked" by LOCK TABLES. --- mysql-test/r/create_or_replace.result | 20 ++++++++++++++++++++ mysql-test/t/create_or_replace.test | 24 ++++++++++++++++++++++++ sql/sql_table.cc | 2 +- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/create_or_replace.result b/mysql-test/r/create_or_replace.result index 646183ebcb1..85602462de5 100644 --- a/mysql-test/r/create_or_replace.result +++ b/mysql-test/r/create_or_replace.result @@ -488,3 +488,23 @@ CREATE OR REPLACE TABLE t1 (i INT); UNLOCK TABLES; INSERT INTO t2 VALUES (1); DROP TABLE t1, t2, t3; +# +# MDEV-11071 - Assertion `thd->transaction.stmt.is_empty()' failed in +# Locked_tables_list::unlock_locked_tables +# +CREATE TEMPORARY TABLE t1(a INT) ENGINE=InnoDB; +CREATE TEMPORARY TABLE t2(a INT); +CREATE TABLE t3(a INT); +LOCK TABLE t2 WRITE; +SELECT * FROM t2; +a +CREATE OR REPLACE TEMPORARY TABLE t1(c INT DEFAULT ''); +ERROR 42000: Invalid default value for 'c' +SELECT * FROM t3; +ERROR HY000: Table 't3' was not locked with LOCK TABLES +CREATE OR REPLACE TEMPORARY TABLE t2(c INT DEFAULT ''); +ERROR 42000: Invalid default value for 'c' +SELECT * FROM t3; +ERROR HY000: Table 't3' was not locked with LOCK TABLES +UNLOCK TABLES; +DROP TABLE t3; diff --git a/mysql-test/t/create_or_replace.test b/mysql-test/t/create_or_replace.test index 8c8ed1c9886..9a1c77f38ee 100644 --- a/mysql-test/t/create_or_replace.test +++ b/mysql-test/t/create_or_replace.test @@ -444,3 +444,27 @@ INSERT INTO t2 VALUES (1); # Cleanup DROP TABLE t1, t2, t3; + +--echo # +--echo # MDEV-11071 - Assertion `thd->transaction.stmt.is_empty()' failed in +--echo # Locked_tables_list::unlock_locked_tables +--echo # +CREATE TEMPORARY TABLE t1(a INT) ENGINE=InnoDB; +CREATE TEMPORARY TABLE t2(a INT); +CREATE TABLE t3(a INT); +LOCK TABLE t2 WRITE; +SELECT * FROM t2; +# drops t2 +--error ER_INVALID_DEFAULT +CREATE OR REPLACE TEMPORARY TABLE t1(c INT DEFAULT ''); +# make sure we didn't leave locked tables mode +--error ER_TABLE_NOT_LOCKED +SELECT * FROM t3; +# drops t1 +--error ER_INVALID_DEFAULT +CREATE OR REPLACE TEMPORARY TABLE t2(c INT DEFAULT ''); +# make sure we didn't leave locked tables mode +--error ER_TABLE_NOT_LOCKED +SELECT * FROM t3; +UNLOCK TABLES; +DROP TABLE t3; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 5d20ad3967c..2302026b18b 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5087,7 +5087,7 @@ err: /* Write log if no error or if we already deleted a table */ if (!result || thd->log_current_statement) { - if (result && create_info->table_was_deleted) + if (result && create_info->table_was_deleted && pos_in_locked_tables) { /* Possible locked table was dropped. We should remove meta data locks