Commit b9fbd102 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-19198 - DBUG assert in CREATE IF NOT EXIST under LOCK TABLES WRITE

Relax the assert condition. A locked table that did existed prior to
CREATE IF NOT EXIST, retains the MDL_NO_SHARED_READ_WRITE MDL lock prio.
parent a6e97dad
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;
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;
......@@ -5615,11 +5615,18 @@ 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
*/
DBUG_ASSERT((create_info->tmp_table()) ||
thd->mdl_context.is_lock_owner(MDL_key::TABLE, table->db,
table->table_name,
MDL_EXCLUSIVE));
MDL_EXCLUSIVE) ||
(thd->locked_tables_mode && pos_in_locked_tables &&
create_info->if_not_exists()));
}
DEBUG_SYNC(thd, "create_table_like_before_binlog");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment