Commit 05a126ed authored by Jon Olav Hauglid's avatar Jon Olav Hauglid

Backport of revno: 2617.76.2

Bug #47107 assert in notify_shared_lock on incorrect CREATE TABLE , HANDLER

Attempts to create a table (using CREATE TABLE, CREATE TABLE LIKE or
CREATE TABLE SELECT statements) which already existed and was opened
by the same connection through HANDLER statement, led to a stalled
connection (for production builds of the server) or to the server being
aborted due to an assertion failure (for debug builds of the server).

This problem was introduced by the new implementation of a metadata
locking subsystem and didn't affect earlier versions of the server.

The cause of the problem was that the HANDLER was not closed by CREATE TABLE
before CREATE tried to open and lock the table. Acquiring an exclusive MDL
lock on the table to be created would therefore fail since HANDLER
already had a shared MDL lock. This triggered an assert as the 
HANDLER and CREATE statements came from the same thread (self-deadlock).

This patch resolves the issue by closing any open HANDLERs on tables
to be created by CREATE TABLE, similar to what is already done for 
DROP and ALTER TABLE.

Test case added to create.test.
parent d40ef57d
...@@ -1961,3 +1961,21 @@ END ;| ...@@ -1961,3 +1961,21 @@ END ;|
ERROR 42000: This version of MySQL doesn't yet support 'multiple triggers with the same action time and event for one table' ERROR 42000: This version of MySQL doesn't yet support 'multiple triggers with the same action time and event for one table'
DROP TABLE t1; DROP TABLE t1;
DROP TABLE B; DROP TABLE B;
#
# Bug #47107 assert in notify_shared_lock on incorrect
# CREATE TABLE , HANDLER
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(f1 integer);
# The following CREATE TABLEs before gave an assert.
HANDLER t1 OPEN AS A;
CREATE TABLE t1 SELECT 1 AS f2;
ERROR 42S01: Table 't1' already exists
HANDLER t1 OPEN AS A;
CREATE TABLE t1(f1 integer);
ERROR 42S01: Table 't1' already exists
CREATE TABLE t2(f1 integer);
HANDLER t1 OPEN AS A;
CREATE TABLE t1 LIKE t2;
ERROR 42S01: Table 't1' already exists
DROP TABLE t2;
DROP TABLE t1;
...@@ -1639,3 +1639,33 @@ END ;| ...@@ -1639,3 +1639,33 @@ END ;|
DROP TABLE t1; DROP TABLE t1;
DROP TABLE B; DROP TABLE B;
--echo #
--echo # Bug #47107 assert in notify_shared_lock on incorrect
--echo # CREATE TABLE , HANDLER
--echo #
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings
CREATE TABLE t1(f1 integer);
--echo # The following CREATE TABLEs before gave an assert.
HANDLER t1 OPEN AS A;
--error ER_TABLE_EXISTS_ERROR
CREATE TABLE t1 SELECT 1 AS f2;
HANDLER t1 OPEN AS A;
--error ER_TABLE_EXISTS_ERROR
CREATE TABLE t1(f1 integer);
CREATE TABLE t2(f1 integer);
HANDLER t1 OPEN AS A;
--error ER_TABLE_EXISTS_ERROR
CREATE TABLE t1 LIKE t2;
DROP TABLE t2;
DROP TABLE t1;
...@@ -2311,6 +2311,12 @@ case SQLCOM_PREPARE: ...@@ -2311,6 +2311,12 @@ case SQLCOM_PREPARE:
thd->work_part_info= part_info; thd->work_part_info= part_info;
} }
#endif #endif
/*
Close any open handlers for the table
*/
mysql_ha_rm_tables(thd, create_table);
if (select_lex->item_list.elements) // With select if (select_lex->item_list.elements) // With select
{ {
select_result *result; select_result *result;
......
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