Skip to content

Commit

Permalink
MDEV-19198 - DBUG assert in CREATE IF NOT EXIST under LOCK TABLES WRITE
Browse files Browse the repository at this point in the history
Fixed the ASSERT to take care of the case when table already existed.
  • Loading branch information
montywi authored and vuvova committed May 19, 2021
1 parent 0bc3a08 commit 0b59320
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
22 changes: 22 additions & 0 deletions mysql-test/main/lock.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
25 changes: 25 additions & 0 deletions mysql-test/main/lock.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
12 changes: 4 additions & 8 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4504,7 +4504,7 @@ int create_table_impl(THD *thd,
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)
Expand Down Expand Up @@ -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) ||
Expand Down

0 comments on commit 0b59320

Please sign in to comment.