From 0b59320d3d2960355ae4afb3a434a5c81c063e12 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 29 Apr 2021 17:40:32 +0300 Subject: [PATCH] MDEV-19198 - DBUG assert in CREATE IF NOT EXIST under LOCK TABLES WRITE Fixed the ASSERT to take care of the case when table already existed. --- mysql-test/main/lock.result | 22 ++++++++++++++++++++++ mysql-test/main/lock.test | 25 +++++++++++++++++++++++++ sql/sql_table.cc | 12 ++++-------- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/mysql-test/main/lock.result b/mysql-test/main/lock.result index 7abeaf035ee..d0adc923563 100644 --- a/mysql-test/main/lock.result +++ b/mysql-test/main/lock.result @@ -535,3 +535,25 @@ DROP TABLE t; # # End of 10.5 tests # +# +# MDEV-19198 Assertion `(create_info->tmp_table()) || ....` +# failed in mysql_create_like_table +# +CREATE TABLE t1 (c INT); +CREATE TABLE t2 (c INT); +LOCK TABLES t1 WRITE, t2 READ; +CREATE TABLE IF NOT EXISTS t1 LIKE t2; +Warnings: +Note 1050 Table 't1' already exists +UNLOCK TABLES; +LOCK TABLES t1 READ , t2 READ; +CREATE TABLE IF NOT EXISTS t1 LIKE t2; +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated +UNLOCK TABLES; +CREATE TABLE IF NOT EXISTS t1 LIKE t2; +Warnings: +Note 1050 Table 't1' already exists +DROP TABLES t1,t2; +# +# End of 10.6 tests +# diff --git a/mysql-test/main/lock.test b/mysql-test/main/lock.test index 8f2435160c3..3e21fb891b8 100644 --- a/mysql-test/main/lock.test +++ b/mysql-test/main/lock.test @@ -651,3 +651,28 @@ DROP TABLE t; --echo # --echo # End of 10.5 tests --echo # + +--echo # +--echo # MDEV-19198 Assertion `(create_info->tmp_table()) || ....` +--echo # failed in mysql_create_like_table +--echo # + +CREATE TABLE t1 (c INT); +CREATE TABLE t2 (c INT); + +LOCK TABLES t1 WRITE, t2 READ; +CREATE TABLE IF NOT EXISTS t1 LIKE t2; +UNLOCK TABLES; + +LOCK TABLES t1 READ , t2 READ; +--error ER_TABLE_NOT_LOCKED_FOR_WRITE +CREATE TABLE IF NOT EXISTS t1 LIKE t2; +UNLOCK TABLES; + +CREATE TABLE IF NOT EXISTS t1 LIKE t2; + +DROP TABLES t1,t2; + +--echo # +--echo # End of 10.6 tests +--echo # diff --git a/sql/sql_table.cc b/sql/sql_table.cc index ef92068c0d2..6be126655fc 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4504,7 +4504,7 @@ warn: in various version of CREATE TABLE statement. @result - 1 unspefied error + 1 unspecifed error 2 error; Don't log create statement 0 ok -1 Table was used with IF NOT EXISTS and table existed (warning, not error) @@ -5203,14 +5203,10 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, { /* Ensure that we have an exclusive lock on target table if we are creating - non-temporary table. - If we're creating non-temporary table, then either - - there is an exclusive lock on the table - or - - there was CREATE IF EXIST, and the table was not created - (it existed), and was previously locked + non-temporary table. We don't have or need the lock if the create failed + because of existing table when using "if exists". */ - DBUG_ASSERT((create_info->tmp_table()) || + DBUG_ASSERT((create_info->tmp_table()) || create_res < 0 || thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db.str, table->table_name.str, MDL_EXCLUSIVE) ||