summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Olav Hauglid <jon.hauglid@sun.com>2009-12-09 13:15:35 +0100
committerJon Olav Hauglid <jon.hauglid@sun.com>2009-12-09 13:15:35 +0100
commit05a126eda1d0fc34440323d707921d4c836c3628 (patch)
tree7685bc95a39aad57e3c54febb2da9b32f6d83a3e
parentd40ef57d80639815fb5c64ef07a37d826b943cb8 (diff)
downloadmariadb-git-05a126eda1d0fc34440323d707921d4c836c3628.tar.gz
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.
-rw-r--r--mysql-test/r/create.result18
-rw-r--r--mysql-test/t/create.test30
-rw-r--r--sql/sql_parse.cc6
3 files changed, 54 insertions, 0 deletions
diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result
index cf424b8b058..90502f94f44 100644
--- a/mysql-test/r/create.result
+++ b/mysql-test/r/create.result
@@ -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'
DROP TABLE t1;
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;
diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test
index c07014bfc19..21778e00ab9 100644
--- a/mysql-test/t/create.test
+++ b/mysql-test/t/create.test
@@ -1639,3 +1639,33 @@ END ;|
DROP TABLE t1;
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;
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 2c5f72c8cf4..056a947f3fa 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2311,6 +2311,12 @@ case SQLCOM_PREPARE:
thd->work_part_info= part_info;
}
#endif
+
+ /*
+ Close any open handlers for the table
+ */
+ mysql_ha_rm_tables(thd, create_table);
+
if (select_lex->item_list.elements) // With select
{
select_result *result;