From 7fd30bf61007af9bfe8114724375da18cabb04a9 Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Fri, 26 Feb 2010 13:40:25 +0100 Subject: Bug #51240 ALTER TABLE of a locked MERGE table fails The problem was that ALTER TABLE on a merge table which was locked using LOCK TABLE ... WRITE, by mistake gave ER_TABLE_NOT_LOCKED_FOR_WRITE. During opening of the table to be ALTERed, open_table() tried to get an upgradable metadata lock. In LOCK TABLEs mode, this lock must already exist (i.e. taken by LOCK TABLE) as new locks of this type cannot be acquired for fear of deadlock. So in LOCK TABLEs mode, open_table() tried to find an existing upgradable lock for the table to be altered. The problem was that open_table() also tried to find upgradable metadata locks for children of merge tables even if no such locks are needed to execute ALTER TABLE on merge tables. This patch fixes the problem by making sure that open tables code only searches for upgradable metadata locks for the merge table and not for the merge children tables. The patch also fixes a related bug where an upgradable metadata lock was aquired outside of LOCK TABLEs mode even if the table in question was temporary. This bug meant that LOCK TABLES or DDL on temporary tables by mistake could be blocked/aborted by locks held on base tables with the same table name by other connections. Test cases added to merge.test and lock_multi.test. --- mysql-test/t/merge.test | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'mysql-test/t/merge.test') diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index f0d8960322e..4035752b72d 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -2089,5 +2089,24 @@ execute stmt; execute stmt; drop table t4, t3, t2, t1; + +--echo # +--echo # Bug#51240 ALTER TABLE of a locked MERGE table fails +--echo # + +--disable_warnings +DROP TABLE IF EXISTS m1, t1; +--enable_warnings + +CREATE TABLE t1 (c1 INT); +CREATE TABLE m1 (c1 INT) ENGINE=MRG_MyISAM UNION=(t1); +LOCK TABLE m1 WRITE; +# This used to cause an error. +ALTER TABLE m1 ADD INDEX (c1); + +UNLOCK TABLES; +DROP TABLE m1, t1; + + --echo End of 6.0 tests -- cgit v1.2.1