List:Commits« Previous MessageNext Message »
From:Mattias Jonsson Date:September 21 2010 11:29pm
Subject:bzr commit into mysql-5.5-bugfixing branch (mattias.jonsson:3210) Bug#56172
View as plain text  
#At file:///Users/mattiasj/mysql-bzr/b56172-55-bf/ based on revid:marc.alff@stripped

 3210 Mattias Jonsson	2010-09-22
      Bug#56172: Server crashes in ha_partition::reset on
                 REBUILD PARTITION under LOCK TABLE
      
      When ALTER PARTITION failed under LOCK TABLE it could crash the server,
      due to it internally altered the locked table directly,
      which was not reverted in case of failure, resulting in bad table definition.
      
      Solved by instead of altering the locked table object and
      its partition_info struct, creating an internal temporary
      intermediate table object used for altering,
      just like the non partitioned mysql_alter_table.
      So if an error occur before the alter operation is complete,
      the original table is not modified at all.
      But if the alter operation have succeeded so far that it
      must be completed as whole,
      the table is properly closed and reopened.
      (The completion on failure is done by the ddl_log.)
     @ mysql-test/suite/parts/inc/partition_fail.inc
        Added tests under LOCK TABLE
     @ mysql-test/suite/parts/r/partition_debug_innodb.result
        Updated results
     @ mysql-test/suite/parts/r/partition_debug_myisam.result
        Updated results
     @ mysql-test/suite/parts/r/partition_special_innodb.result
        updated result
     @ mysql-test/suite/parts/t/partition_debug_innodb-master.opt
        Allowing stack-trace and core-files since the use of _exit() instead of abort().
     @ mysql-test/suite/parts/t/partition_debug_myisam-master.opt
        Allowing stack-trace and core-files since the use of _exit() instead of abort().
     @ mysql-test/suite/parts/t/partition_special_innodb.test
        changing comment, since this patch also fixes this.
     @ sql/sql_partition.cc
        Simulating crash with _exit() instead of abort() to avoid core-files on expected crashes.
        Removed unused arguments to fast_end_partition.
        Opening a intermediate table in prep_alter_part_table, instead of altering
        (a possible locked) normally opened table.
        That way we do not have to do anything more than close
        the intermediate table on error,
        leaving the ordinary table opened and locked.
        Also making sure that the intermediate table are
        closed/destroyed on failure. If no error occur
        it is later destroyed in the end of fast_alter_partition_table.
        Added ha_external_lock to make sure MyISAM flushed the index file
        after copying the partitions.
        This also leads to removal of the special close and removal from
        the table cache for other instances of the table.
     @ sql/sql_partition.h
        Changed the arguments for prep_alter_part_table and
        fast_alter_partition_table to use an intermediate table
        instead of altering a (possibly locked) normal table.
     @ sql/sql_table.cc
        Using an intermediate table created in prep_alter_part_table
        to be used in fast_alter_partition_table, also closing/destroying
        it on failure.

    removed:
      mysql-test/suite/parts/t/partition_debug_myisam-master.opt
    modified:
      mysql-test/suite/parts/inc/partition_fail.inc
      mysql-test/suite/parts/r/partition_debug_innodb.result
      mysql-test/suite/parts/r/partition_debug_myisam.result
      mysql-test/suite/parts/r/partition_special_innodb.result
      mysql-test/suite/parts/t/partition_debug_innodb-master.opt
      mysql-test/suite/parts/t/partition_special_innodb.test
      sql/sql_partition.cc
      sql/sql_partition.h
      sql/sql_table.cc
=== modified file 'mysql-test/suite/parts/inc/partition_fail.inc'
--- a/mysql-test/suite/parts/inc/partition_fail.inc	2010-08-13 07:50:25 +0000
+++ b/mysql-test/suite/parts/inc/partition_fail.inc	2010-09-21 23:29:26 +0000
@@ -16,3 +16,23 @@ SHOW CREATE TABLE t1;
 --sorted_result
 SELECT * FROM t1;
 DROP TABLE t1;
+
+--echo # Same test under LOCK TABLE
+--eval $create_statement
+--eval $insert_statement
+--echo # State before failure
+--list_files $DATADIR/test
+SHOW CREATE TABLE t1;
+--sorted_result
+SELECT * FROM t1;
+LOCK TABLE t1 WRITE;
+--disable_abort_on_error
+--eval $fail_statement
+--enable_abort_on_error
+--echo # State after failure
+--list_files $DATADIR/test
+SHOW CREATE TABLE t1;
+--sorted_result
+SELECT * FROM t1;
+UNLOCK TABLES;
+DROP TABLE t1;

=== modified file 'mysql-test/suite/parts/r/partition_debug_innodb.result'
--- a/mysql-test/suite/parts/r/partition_debug_innodb.result	2010-08-13 07:50:25 +0000
+++ b/mysql-test/suite/parts/r/partition_debug_innodb.result	2010-09-21 23:29:26 +0000
@@ -747,8 +747,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_1";
-SET SESSION debug="+d,fail_add_partition_2";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -779,6 +778,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
@@ -806,9 +806,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_2";
-SET SESSION debug="+d,fail_add_partition_3";
+SET SESSION debug="-d,fail_add_partition_1";
+SET SESSION debug="+d,fail_add_partition_2";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -867,8 +868,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_3";
-SET SESSION debug="+d,fail_add_partition_4";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -899,6 +899,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
@@ -926,9 +927,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_4";
-SET SESSION debug="+d,fail_add_partition_5";
+SET SESSION debug="-d,fail_add_partition_2";
+SET SESSION debug="+d,fail_add_partition_3";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -987,8 +989,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_5";
-SET SESSION debug="+d,fail_add_partition_6";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -1019,6 +1020,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
@@ -1046,9 +1048,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_6";
-SET SESSION debug="+d,fail_add_partition_7";
+SET SESSION debug="-d,fail_add_partition_3";
+SET SESSION debug="+d,fail_add_partition_4";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -1107,8 +1110,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_7";
-SET SESSION debug="+d,fail_add_partition_8";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -1139,13 +1141,13 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1156,8 +1158,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -1168,9 +1169,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_8";
-SET SESSION debug="+d,fail_add_partition_9";
+SET SESSION debug="-d,fail_add_partition_4";
+SET SESSION debug="+d,fail_add_partition_5";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -1207,7 +1209,6 @@ ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1218,8 +1219,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -1231,8 +1231,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_9";
-SET SESSION debug="+d,fail_add_partition_10";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -1263,13 +1262,13 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1280,8 +1279,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -1292,17 +1290,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_10";
-# Test DROP PARTITION
-SET SESSION debug="+d,crash_drop_partition_1";
+SET SESSION debug="-d,fail_add_partition_5";
+SET SESSION debug="+d,fail_add_partition_6";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1326,14 +1324,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.ibd
-t1#P#p10.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1358,15 +1352,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_1";
-SET SESSION debug="+d,crash_drop_partition_2";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1390,16 +1383,11 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.ibd
-t1#P#p10.ibd
-t1.frm
-t1.par
-# State after crash recovery
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1423,16 +1411,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_2";
-SET SESSION debug="+d,crash_drop_partition_3";
+SET SESSION debug="-d,fail_add_partition_6";
+SET SESSION debug="+d,fail_add_partition_7";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1456,16 +1445,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.ibd
-t1#P#p10.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1490,15 +1473,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_3";
-SET SESSION debug="+d,crash_drop_partition_4";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1522,19 +1504,15 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
 t1.par
-# State after crash recovery
-t1#P#p0.ibd
-t1.frm
-t1.par
 SHOW CREATE TABLE t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
@@ -1542,23 +1520,29 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_4";
-SET SESSION debug="+d,crash_drop_partition_5";
+SET SESSION debug="-d,fail_add_partition_7";
+SET SESSION debug="+d,fail_add_partition_8";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1582,17 +1566,13 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1.frm
-t1.par
-# State after crash recovery
-t1#P#p0.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1602,23 +1582,28 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_5";
-SET SESSION debug="+d,crash_drop_partition_6";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1642,17 +1627,14 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1.frm
-t1.par
-# State after crash recovery
-t1#P#p0.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1662,23 +1644,30 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_6";
-SET SESSION debug="+d,crash_drop_partition_7";
+SET SESSION debug="-d,fail_add_partition_8";
+SET SESSION debug="+d,fail_add_partition_9";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1702,15 +1691,13 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1.frm
-t1.par
-# State after crash recovery
-t1#P#p0.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1720,23 +1707,28 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_7";
-SET SESSION debug="+d,crash_drop_partition_8";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1760,14 +1752,14 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.ibd
-t1.frm
-t1.par
-# State after crash recovery
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1777,23 +1769,30 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_8";
-SET SESSION debug="+d,crash_drop_partition_9";
+SET SESSION debug="-d,fail_add_partition_9";
+SET SESSION debug="+d,fail_add_partition_10";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1817,14 +1816,13 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1834,17 +1832,21 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_9";
-# Error recovery DROP PARTITION
-SET SESSION debug="+d,fail_drop_partition_1";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -1875,11 +1877,14 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1890,7 +1895,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -1901,16 +1907,18 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_1";
-SET SESSION debug="+d,fail_drop_partition_2";
+SET SESSION debug="-d,fail_add_partition_10";
+# Test DROP PARTITION
+SET SESSION debug="+d,crash_drop_partition_1";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1935,8 +1943,13 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1961,15 +1974,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_2";
-SET SESSION debug="+d,fail_drop_partition_3";
+SET SESSION debug="-d,crash_drop_partition_1";
+SET SESSION debug="+d,crash_drop_partition_2";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -1994,8 +2007,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2020,15 +2040,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_3";
-SET SESSION debug="+d,fail_drop_partition_4";
+SET SESSION debug="-d,crash_drop_partition_2";
+SET SESSION debug="+d,crash_drop_partition_3";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2053,9 +2073,17 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.ibd
+t1#P#p10.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -2065,23 +2093,28 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_4";
-SET SESSION debug="+d,fail_drop_partition_5";
+SET SESSION debug="-d,crash_drop_partition_3";
+SET SESSION debug="+d,crash_drop_partition_4";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2106,8 +2139,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.ibd
 t1.frm
 t1.par
@@ -2126,15 +2166,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_5";
-SET SESSION debug="+d,fail_drop_partition_6";
+SET SESSION debug="-d,crash_drop_partition_4";
+SET SESSION debug="+d,crash_drop_partition_5";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2159,8 +2199,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.ibd
 t1.frm
 t1.par
@@ -2179,15 +2226,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_6";
-SET SESSION debug="+d,fail_drop_partition_7";
+SET SESSION debug="-d,crash_drop_partition_5";
+SET SESSION debug="+d,crash_drop_partition_6";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2212,8 +2259,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.ibd
 t1.frm
 t1.par
@@ -2232,15 +2286,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_7";
-SET SESSION debug="+d,fail_drop_partition_8";
+SET SESSION debug="-d,crash_drop_partition_6";
+SET SESSION debug="+d,crash_drop_partition_7";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2265,8 +2319,13 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.ibd
 t1.frm
 t1.par
@@ -2285,15 +2344,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_8";
-SET SESSION debug="+d,fail_drop_partition_9";
+SET SESSION debug="-d,crash_drop_partition_7";
+SET SESSION debug="+d,crash_drop_partition_8";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2318,8 +2377,12 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.ibd
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.ibd
 t1.frm
 t1.par
@@ -2338,10 +2401,8 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_9";
-# Test change partition (REORGANIZE/REBUILD/COALESCE
-# or ADD HASH PARTITION).
-SET SESSION debug="+d,crash_change_partition_1";
+SET SESSION debug="-d,crash_drop_partition_8";
+SET SESSION debug="+d,crash_drop_partition_9";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -2372,17 +2433,68 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
-(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
-PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ALTER TABLE t1 DROP PARTITION p10;
 ERROR HY000: Lost connection to MySQL server during query
 # State after crash (before recovery)
 t1#P#p0.ibd
-t1#P#p10.ibd
 t1.frm
 t1.par
 # State after crash recovery
 t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_drop_partition_9";
+# Error recovery DROP PARTITION
+SET SESSION debug="+d,fail_drop_partition_1";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
 t1.par
@@ -2406,15 +2518,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_1";
-SET SESSION debug="+d,crash_change_partition_2";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2438,18 +2549,1851 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
-(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
-PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
 t1.par
-# State after crash recovery
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_1";
+SET SESSION debug="+d,fail_drop_partition_2";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_2";
+SET SESSION debug="+d,fail_drop_partition_3";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_3";
+SET SESSION debug="+d,fail_drop_partition_4";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_4";
+SET SESSION debug="+d,fail_drop_partition_5";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_5";
+SET SESSION debug="+d,fail_drop_partition_6";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_6";
+SET SESSION debug="+d,fail_drop_partition_7";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_7";
+SET SESSION debug="+d,fail_drop_partition_8";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_8";
+SET SESSION debug="+d,fail_drop_partition_9";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_9";
+# Test change partition (REORGANIZE/REBUILD/COALESCE
+# or ADD HASH PARTITION).
+SET SESSION debug="+d,crash_change_partition_1";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_1";
+SET SESSION debug="+d,crash_change_partition_2";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_2";
+SET SESSION debug="+d,crash_change_partition_3";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_3";
+SET SESSION debug="+d,crash_change_partition_4";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10#TMP#.ibd
+t1#P#p10.ibd
+t1#P#p20#TMP#.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_4";
+SET SESSION debug="+d,crash_change_partition_5";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10#TMP#.ibd
+t1#P#p10.ibd
+t1#P#p20#TMP#.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_5";
+SET SESSION debug="+d,crash_change_partition_6";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10#TMP#.ibd
+t1#P#p10.ibd
+t1#P#p20#TMP#.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_6";
+SET SESSION debug="+d,crash_change_partition_7";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.ibd
+t1#P#p10#TMP#.ibd
+t1#P#p10.ibd
+t1#P#p20#TMP#.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_7";
+SET SESSION debug="+d,crash_change_partition_8";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.ibd
+t1#P#p10#TMP#.ibd
+t1#P#p10.ibd
+t1#P#p20#TMP#.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_8";
+SET SESSION debug="+d,crash_change_partition_9";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.ibd
+t1#P#p10#TMP#.ibd
+t1#P#p10.ibd
+t1#P#p20#TMP#.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_9";
+SET SESSION debug="+d,crash_change_partition_10";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.ibd
+t1#P#p10#TMP#.ibd
+t1#P#p10.ibd
+t1#P#p20#TMP#.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_10";
+SET SESSION debug="+d,crash_change_partition_11";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_11";
+SET SESSION debug="+d,crash_change_partition_12";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1#P#p20.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_12";
+# Error recovery change partition (REORGANIZE/REBUILD/COALESCE
+# or ADD HASH PARTITION).
+SET SESSION debug="+d,fail_change_partition_1";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'InnoDB'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.ibd
+t1#P#p10.ibd
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2473,16 +4417,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_2";
-SET SESSION debug="+d,crash_change_partition_3";
+SET SESSION debug="-d,fail_change_partition_1";
+SET SESSION debug="+d,fail_change_partition_2";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2509,15 +4454,8 @@ a	b
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.ibd
-t1#P#p10.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2542,15 +4480,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_3";
-SET SESSION debug="+d,crash_change_partition_4";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2574,20 +4511,12 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.ibd
-t1#P#p10#TMP#.ibd
-t1#P#p10.ibd
-t1#P#p20#TMP#.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2611,16 +4540,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_4";
-SET SESSION debug="+d,crash_change_partition_5";
+SET SESSION debug="-d,fail_change_partition_2";
+SET SESSION debug="+d,fail_change_partition_3";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2647,17 +4577,8 @@ a	b
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.ibd
-t1#P#p10#TMP#.ibd
-t1#P#p10.ibd
-t1#P#p20#TMP#.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2682,15 +4603,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_5";
-SET SESSION debug="+d,crash_change_partition_6";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2714,20 +4634,12 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.ibd
-t1#P#p10#TMP#.ibd
-t1#P#p10.ibd
-t1#P#p20#TMP#.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2751,16 +4663,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_6";
-SET SESSION debug="+d,crash_change_partition_7";
+SET SESSION debug="-d,fail_change_partition_3";
+SET SESSION debug="+d,fail_change_partition_4";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2787,20 +4700,10 @@ a	b
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.ibd
-t1#P#p10#TMP#.ibd
-t1#P#p10.ibd
-t1#P#p20#TMP#.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -2811,8 +4714,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -2824,15 +4726,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_7";
-SET SESSION debug="+d,crash_change_partition_8";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2856,23 +4757,14 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.ibd
-t1#P#p10#TMP#.ibd
-t1#P#p10.ibd
-t1#P#p20#TMP#.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -2883,8 +4775,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -2895,16 +4786,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_8";
-SET SESSION debug="+d,crash_change_partition_9";
+SET SESSION debug="-d,fail_change_partition_4";
+SET SESSION debug="+d,fail_change_partition_5";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2931,18 +4823,10 @@ a	b
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.ibd
-t1#P#p10#TMP#.ibd
-t1#P#p10.ibd
-t1#P#p20#TMP#.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -2953,8 +4837,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -2966,15 +4849,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_9";
-SET SESSION debug="+d,crash_change_partition_10";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -2998,21 +4880,14 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.ibd
-t1#P#p10#TMP#.ibd
-t1#P#p10.ibd
-t1#P#p20#TMP#.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
-t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3023,8 +4898,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3035,16 +4909,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_10";
-SET SESSION debug="+d,crash_change_partition_11";
+SET SESSION debug="-d,fail_change_partition_5";
+SET SESSION debug="+d,fail_change_partition_6";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -3071,14 +4946,8 @@ a	b
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.ibd
-t1#P#p10.ibd
-t1#P#p20.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1#P#p20.ibd
@@ -3105,15 +4974,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_11";
-SET SESSION debug="+d,crash_change_partition_12";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1.frm
@@ -3137,17 +5005,12 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.ibd
-t1#P#p10.ibd
-t1#P#p20.ibd
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
 t1#P#p20.ibd
@@ -3173,11 +5036,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_12";
-# Error recovery change partition (REORGANIZE/REBUILD/COALESCE
-# or ADD HASH PARTITION).
-SET SESSION debug="+d,fail_change_partition_1";
+SET SESSION debug="-d,fail_change_partition_6";
+SET SESSION debug="+d,fail_change_partition_7";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3215,6 +5077,7 @@ ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3225,7 +5088,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3237,8 +5101,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_1";
-SET SESSION debug="+d,fail_change_partition_2";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3269,6 +5132,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3276,6 +5140,7 @@ ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3286,7 +5151,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3297,9 +5163,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_2";
-SET SESSION debug="+d,fail_change_partition_3";
+SET SESSION debug="-d,fail_change_partition_7";
+SET SESSION debug="+d,fail_change_partition_8";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3337,6 +5204,7 @@ ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3347,7 +5215,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3359,8 +5228,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_3";
-SET SESSION debug="+d,fail_change_partition_4";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3391,6 +5259,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3398,6 +5267,7 @@ ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3408,7 +5278,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3419,9 +5290,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_4";
-SET SESSION debug="+d,fail_change_partition_5";
+SET SESSION debug="-d,fail_change_partition_8";
+SET SESSION debug="+d,fail_change_partition_9";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3459,6 +5331,7 @@ ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3469,7 +5342,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3481,8 +5355,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_5";
-SET SESSION debug="+d,fail_change_partition_6";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3513,6 +5386,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3520,6 +5394,7 @@ ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.ibd
 t1#P#p10.ibd
+t1#P#p20.ibd
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3530,7 +5405,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = InnoDB,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = InnoDB) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = InnoDB,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = InnoDB) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3541,9 +5417,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_6";
-SET SESSION debug="+d,fail_change_partition_7";
+SET SESSION debug="-d,fail_change_partition_9";
+SET SESSION debug="+d,fail_change_partition_10";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3605,8 +5482,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_7";
-SET SESSION debug="+d,fail_change_partition_8";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3637,6 +5513,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3667,9 +5544,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_8";
-SET SESSION debug="+d,fail_change_partition_9";
+SET SESSION debug="-d,fail_change_partition_10";
+SET SESSION debug="+d,fail_change_partition_11";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3731,8 +5609,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_9";
-SET SESSION debug="+d,fail_change_partition_10";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3763,6 +5640,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3793,9 +5671,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_10";
-SET SESSION debug="+d,fail_change_partition_11";
+SET SESSION debug="-d,fail_change_partition_11";
+SET SESSION debug="+d,fail_change_partition_12";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3857,8 +5736,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_11";
-SET SESSION debug="+d,fail_change_partition_12";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'InnoDB'
 PARTITION BY LIST (a)
@@ -3889,6 +5767,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3919,5 +5798,6 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
 SET SESSION debug="-d,fail_change_partition_12";

=== modified file 'mysql-test/suite/parts/r/partition_debug_myisam.result'
--- a/mysql-test/suite/parts/r/partition_debug_myisam.result	2010-08-13 07:50:25 +0000
+++ b/mysql-test/suite/parts/r/partition_debug_myisam.result	2010-09-21 23:29:26 +0000
@@ -817,8 +817,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_1";
-SET SESSION debug="+d,fail_add_partition_2";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -851,6 +850,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
@@ -880,9 +880,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_2";
-SET SESSION debug="+d,fail_add_partition_3";
+SET SESSION debug="-d,fail_add_partition_1";
+SET SESSION debug="+d,fail_add_partition_2";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -945,8 +946,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_3";
-SET SESSION debug="+d,fail_add_partition_4";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -979,6 +979,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
@@ -1008,9 +1009,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_4";
-SET SESSION debug="+d,fail_add_partition_5";
+SET SESSION debug="-d,fail_add_partition_2";
+SET SESSION debug="+d,fail_add_partition_3";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -1073,8 +1075,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_5";
-SET SESSION debug="+d,fail_add_partition_6";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -1107,6 +1108,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
@@ -1136,9 +1138,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_6";
-SET SESSION debug="+d,fail_add_partition_7";
+SET SESSION debug="-d,fail_add_partition_3";
+SET SESSION debug="+d,fail_add_partition_4";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -1201,8 +1204,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_7";
-SET SESSION debug="+d,fail_add_partition_8";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -1235,6 +1237,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
@@ -1243,8 +1246,6 @@ t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1#P#p20.MYD
-t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1255,8 +1256,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -1267,9 +1267,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_8";
-SET SESSION debug="+d,fail_add_partition_9";
+SET SESSION debug="-d,fail_add_partition_4";
+SET SESSION debug="+d,fail_add_partition_5";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -1310,8 +1311,6 @@ t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1#P#p20.MYD
-t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1322,8 +1321,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -1335,8 +1333,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_9";
-SET SESSION debug="+d,fail_add_partition_10";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -1369,6 +1366,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 ADD PARTITION
 (PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
@@ -1377,8 +1375,6 @@ t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1#P#p20.MYD
-t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1389,8 +1385,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -1401,17 +1396,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_add_partition_10";
-# Test DROP PARTITION
-SET SESSION debug="+d,crash_drop_partition_1";
+SET SESSION debug="-d,fail_add_partition_5";
+SET SESSION debug="+d,fail_add_partition_6";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1437,16 +1432,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1473,15 +1462,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_1";
-SET SESSION debug="+d,crash_drop_partition_2";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1507,18 +1495,11 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1.frm
-t1.par
-# State after crash recovery
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1544,16 +1525,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_2";
-SET SESSION debug="+d,crash_drop_partition_3";
+SET SESSION debug="-d,fail_add_partition_6";
+SET SESSION debug="+d,fail_add_partition_7";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1579,18 +1561,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1617,15 +1591,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_3";
-SET SESSION debug="+d,crash_drop_partition_4";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1651,22 +1624,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
 t1.frm
 t1.par
-# State after crash recovery
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1.frm
-t1.par
 SHOW CREATE TABLE t1;
 Table	Create Table
 t1	CREATE TABLE `t1` (
@@ -1674,23 +1642,29 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_4";
-SET SESSION debug="+d,crash_drop_partition_5";
+SET SESSION debug="-d,fail_add_partition_7";
+SET SESSION debug="+d,fail_add_partition_8";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1716,20 +1690,16 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1.frm
-t1.par
-# State after crash recovery
-t1#P#p0.MYD
-t1#P#p0.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1739,23 +1709,28 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_5";
-SET SESSION debug="+d,crash_drop_partition_6";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1781,20 +1756,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1.frm
-t1.par
-# State after crash recovery
-t1#P#p0.MYD
-t1#P#p0.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1804,23 +1776,30 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_6";
-SET SESSION debug="+d,crash_drop_partition_7";
+SET SESSION debug="-d,fail_add_partition_8";
+SET SESSION debug="+d,fail_add_partition_9";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1846,18 +1825,16 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1.frm
-t1.par
-# State after crash recovery
-t1#P#p0.MYD
-t1#P#p0.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1867,23 +1844,28 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_7";
-SET SESSION debug="+d,crash_drop_partition_8";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1909,16 +1891,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1.frm
-t1.par
-# State after crash recovery
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1928,23 +1911,30 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_8";
-SET SESSION debug="+d,crash_drop_partition_9";
+SET SESSION debug="-d,fail_add_partition_9";
+SET SESSION debug="+d,fail_add_partition_10";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -1970,16 +1960,16 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -1989,17 +1979,21 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_drop_partition_9";
-# Error recovery DROP PARTITION
-SET SESSION debug="+d,fail_drop_partition_1";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -2032,13 +2026,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 DROP PARTITION p10;
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 ADD PARTITION
+(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
 ERROR HY000: Unknown error
 # State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -2049,7 +2047,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -2060,16 +2059,18 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_1";
-SET SESSION debug="+d,fail_drop_partition_2";
+SET SESSION debug="-d,fail_add_partition_10";
+# Test DROP PARTITION
+SET SESSION debug="+d,crash_drop_partition_1";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2096,8 +2097,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2124,15 +2132,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_2";
-SET SESSION debug="+d,fail_drop_partition_3";
+SET SESSION debug="-d,crash_drop_partition_1";
+SET SESSION debug="+d,crash_drop_partition_2";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2159,8 +2167,17 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2187,15 +2204,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_3";
-SET SESSION debug="+d,fail_drop_partition_4";
+SET SESSION debug="-d,crash_drop_partition_2";
+SET SESSION debug="+d,crash_drop_partition_3";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2222,10 +2239,21 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.MYD
 t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -2235,23 +2263,28 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_4";
-SET SESSION debug="+d,fail_drop_partition_5";
+SET SESSION debug="-d,crash_drop_partition_3";
+SET SESSION debug="+d,crash_drop_partition_4";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2278,8 +2311,17 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1.frm
@@ -2299,15 +2341,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_5";
-SET SESSION debug="+d,fail_drop_partition_6";
+SET SESSION debug="-d,crash_drop_partition_4";
+SET SESSION debug="+d,crash_drop_partition_5";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2334,8 +2376,17 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1.frm
@@ -2355,15 +2406,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_6";
-SET SESSION debug="+d,fail_drop_partition_7";
+SET SESSION debug="-d,crash_drop_partition_5";
+SET SESSION debug="+d,crash_drop_partition_6";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2390,8 +2441,17 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1.frm
@@ -2411,15 +2471,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_7";
-SET SESSION debug="+d,fail_drop_partition_8";
+SET SESSION debug="-d,crash_drop_partition_6";
+SET SESSION debug="+d,crash_drop_partition_7";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2446,8 +2506,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1.frm
@@ -2467,15 +2534,15 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_8";
-SET SESSION debug="+d,fail_drop_partition_9";
+SET SESSION debug="-d,crash_drop_partition_7";
+SET SESSION debug="+d,crash_drop_partition_8";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before failure
+# State before crash
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2502,8 +2569,13 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 ALTER TABLE t1 DROP PARTITION p10;
-ERROR HY000: Unknown error
-# State after failure
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+# State after crash recovery
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1.frm
@@ -2523,10 +2595,8 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_drop_partition_9";
-# Test change partition (REORGANIZE/REBUILD/COALESCE
-# or ADD HASH PARTITION).
-SET SESSION debug="+d,crash_change_partition_1";
+SET SESSION debug="-d,crash_drop_partition_8";
+SET SESSION debug="+d,crash_drop_partition_9";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -2559,22 +2629,16 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
-(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
-PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ALTER TABLE t1 DROP PARTITION p10;
 ERROR HY000: Lost connection to MySQL server during query
 # State after crash (before recovery)
 t1#P#p0.MYD
 t1#P#p0.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
 t1.frm
 t1.par
 # State after crash recovery
 t1#P#p0.MYD
 t1#P#p0.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -2584,28 +2648,24 @@ t1	CREATE TABLE `t1` (
   `b` varchar(64) DEFAULT NULL
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
-(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
-11	Original from partition p1
-12	Original from partition p1
-13	Original from partition p1
-14	Original from partition p1
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_1";
-SET SESSION debug="+d,crash_change_partition_2";
+SET SESSION debug="-d,crash_drop_partition_9";
+# Error recovery DROP PARTITION
+SET SESSION debug="+d,fail_drop_partition_1";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2631,20 +2691,9 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
-(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
-PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2671,15 +2720,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_2";
-SET SESSION debug="+d,crash_change_partition_3";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2705,20 +2753,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
-(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
-PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1.frm
-t1.par
-# State after crash recovery
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2744,16 +2782,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_3";
-SET SESSION debug="+d,crash_change_partition_4";
+SET SESSION debug="-d,fail_drop_partition_1";
+SET SESSION debug="+d,fail_drop_partition_2";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2779,24 +2818,2072 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
-ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
-(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_2";
+SET SESSION debug="+d,fail_drop_partition_3";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_3";
+SET SESSION debug="+d,fail_drop_partition_4";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_4";
+SET SESSION debug="+d,fail_drop_partition_5";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_5";
+SET SESSION debug="+d,fail_drop_partition_6";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_6";
+SET SESSION debug="+d,fail_drop_partition_7";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_7";
+SET SESSION debug="+d,fail_drop_partition_8";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_8";
+SET SESSION debug="+d,fail_drop_partition_9";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 DROP PARTITION p10;
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_drop_partition_9";
+# Test change partition (REORGANIZE/REBUILD/COALESCE
+# or ADD HASH PARTITION).
+SET SESSION debug="+d,crash_change_partition_1";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_1";
+SET SESSION debug="+d,crash_change_partition_2";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_2";
+SET SESSION debug="+d,crash_change_partition_3";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_3";
+SET SESSION debug="+d,crash_change_partition_4";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10#TMP#.MYD
+t1#P#p10#TMP#.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20#TMP#.MYD
+t1#P#p20#TMP#.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_4";
+SET SESSION debug="+d,crash_change_partition_5";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10#TMP#.MYD
+t1#P#p10#TMP#.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20#TMP#.MYD
+t1#P#p20#TMP#.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_5";
+SET SESSION debug="+d,crash_change_partition_6";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10#TMP#.MYD
+t1#P#p10#TMP#.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20#TMP#.MYD
+t1#P#p20#TMP#.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_6";
+SET SESSION debug="+d,crash_change_partition_7";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sql-t1.frm
+#sql-t1.par
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10#TMP#.MYD
+t1#P#p10#TMP#.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20#TMP#.MYD
+t1#P#p20#TMP#.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_7";
+SET SESSION debug="+d,crash_change_partition_8";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10#TMP#.MYD
+t1#P#p10#TMP#.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20#TMP#.MYD
+t1#P#p20#TMP#.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_8";
+SET SESSION debug="+d,crash_change_partition_9";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10#TMP#.MYD
+t1#P#p10#TMP#.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20#TMP#.MYD
+t1#P#p20#TMP#.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_9";
+SET SESSION debug="+d,crash_change_partition_10";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10#TMP#.MYD
+t1#P#p10#TMP#.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20#TMP#.MYD
+t1#P#p20#TMP#.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_10";
+SET SESSION debug="+d,crash_change_partition_11";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_11";
+SET SESSION debug="+d,crash_change_partition_12";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
+t1.frm
+t1.par
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+SET SESSION debug="-d,crash_change_partition_12";
+# Error recovery change partition (REORGANIZE/REBUILD/COALESCE
+# or ADD HASH PARTITION).
+SET SESSION debug="+d,fail_change_partition_1";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
-t1#P#p10#TMP#.MYD
-t1#P#p10#TMP#.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1#P#p20#TMP#.MYD
-t1#P#p20#TMP#.MYI
 t1.frm
 t1.par
-# State after crash recovery
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+UNLOCK TABLES;
+DROP TABLE t1;
+SET SESSION debug="-d,fail_change_partition_1";
+SET SESSION debug="+d,fail_change_partition_2";
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+DROP TABLE t1;
+# Same test under LOCK TABLE
+CREATE TABLE t1 (a INT, b VARCHAR(64))
+ENGINE = 'MyISAM'
+PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
+PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
+INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p10.MYD
+t1#P#p10.MYI
+t1.frm
+t1.par
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) DEFAULT NULL,
+  `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY LIST (a)
+(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+SELECT * FROM t1;
+a	b
+1	Original from partition p0
+11	Original from partition p1
+12	Original from partition p1
+13	Original from partition p1
+14	Original from partition p1
+2	Original from partition p0
+3	Original from partition p0
+4	Original from partition p0
+LOCK TABLE t1 WRITE;
+ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
+(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
+PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2822,16 +4909,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_4";
-SET SESSION debug="+d,crash_change_partition_5";
+SET SESSION debug="-d,fail_change_partition_2";
+SET SESSION debug="+d,fail_change_partition_3";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2860,21 +4948,8 @@ a	b
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10#TMP#.MYD
-t1#P#p10#TMP#.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1#P#p20#TMP#.MYD
-t1#P#p20#TMP#.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2901,15 +4976,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_5";
-SET SESSION debug="+d,crash_change_partition_6";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2935,24 +5009,12 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10#TMP#.MYD
-t1#P#p10#TMP#.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1#P#p20#TMP#.MYD
-t1#P#p20#TMP#.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -2978,16 +5040,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_6";
-SET SESSION debug="+d,crash_change_partition_7";
+SET SESSION debug="-d,fail_change_partition_3";
+SET SESSION debug="+d,fail_change_partition_4";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -3016,27 +5079,12 @@ a	b
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10#TMP#.MYD
-t1#P#p10#TMP#.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1#P#p20#TMP#.MYD
-t1#P#p20#TMP#.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1#P#p20.MYD
-t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3047,8 +5095,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3060,15 +5107,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_7";
-SET SESSION debug="+d,crash_change_partition_8";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -3094,30 +5140,16 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-#sql-t1.frm
-#sql-t1.par
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10#TMP#.MYD
-t1#P#p10#TMP#.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1#P#p20#TMP#.MYD
-t1#P#p20#TMP#.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1#P#p20.MYD
-t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3128,8 +5160,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3140,16 +5171,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_8";
-SET SESSION debug="+d,crash_change_partition_9";
+SET SESSION debug="-d,fail_change_partition_4";
+SET SESSION debug="+d,fail_change_partition_5";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -3178,25 +5210,12 @@ a	b
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10#TMP#.MYD
-t1#P#p10#TMP#.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1#P#p20#TMP#.MYD
-t1#P#p20#TMP#.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1#P#p20.MYD
-t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3207,8 +5226,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3220,15 +5238,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_9";
-SET SESSION debug="+d,crash_change_partition_10";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -3254,28 +5271,16 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10#TMP#.MYD
-t1#P#p10#TMP#.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1#P#p20#TMP#.MYD
-t1#P#p20#TMP#.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
-t1#P#p20.MYD
-t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3286,8 +5291,7 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
- PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3298,16 +5302,17 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_10";
-SET SESSION debug="+d,crash_change_partition_11";
+SET SESSION debug="-d,fail_change_partition_5";
+SET SESSION debug="+d,fail_change_partition_6";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -3336,17 +5341,8 @@ a	b
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1#P#p20.MYD
-t1#P#p20.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -3376,15 +5372,14 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_11";
-SET SESSION debug="+d,crash_change_partition_12";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9),
 PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19));
 INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1");
-# State before crash
+# State before failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -3410,20 +5405,12 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
-ERROR HY000: Lost connection to MySQL server during query
-# State after crash (before recovery)
-t1#P#p0.MYD
-t1#P#p0.MYI
-t1#P#p10.MYD
-t1#P#p10.MYI
-t1#P#p20.MYD
-t1#P#p20.MYI
-t1.frm
-t1.par
-# State after crash recovery
+ERROR HY000: Unknown error
+# State after failure
 t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
@@ -3452,11 +5439,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,crash_change_partition_12";
-# Error recovery change partition (REORGANIZE/REBUILD/COALESCE
-# or ADD HASH PARTITION).
-SET SESSION debug="+d,fail_change_partition_1";
+SET SESSION debug="-d,fail_change_partition_6";
+SET SESSION debug="+d,fail_change_partition_7";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -3498,6 +5484,8 @@ t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3508,7 +5496,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3520,8 +5509,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_1";
-SET SESSION debug="+d,fail_change_partition_2";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -3554,6 +5542,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3563,6 +5552,8 @@ t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3573,7 +5564,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3584,9 +5576,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_2";
-SET SESSION debug="+d,fail_change_partition_3";
+SET SESSION debug="-d,fail_change_partition_7";
+SET SESSION debug="+d,fail_change_partition_8";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -3628,6 +5621,8 @@ t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3638,7 +5633,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3650,8 +5646,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_3";
-SET SESSION debug="+d,fail_change_partition_4";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -3684,6 +5679,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3693,6 +5689,8 @@ t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3703,7 +5701,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3714,9 +5713,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_4";
-SET SESSION debug="+d,fail_change_partition_5";
+SET SESSION debug="-d,fail_change_partition_8";
+SET SESSION debug="+d,fail_change_partition_9";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -3758,6 +5758,8 @@ t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3768,7 +5770,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3780,8 +5783,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_5";
-SET SESSION debug="+d,fail_change_partition_6";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -3814,6 +5816,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3823,6 +5826,8 @@ t1#P#p0.MYD
 t1#P#p0.MYI
 t1#P#p10.MYD
 t1#P#p10.MYI
+t1#P#p20.MYD
+t1#P#p20.MYI
 t1.frm
 t1.par
 SHOW CREATE TABLE t1;
@@ -3833,7 +5838,8 @@ t1	CREATE TABLE `t1` (
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 /*!50100 PARTITION BY LIST (a)
 (PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9) ENGINE = MyISAM,
- PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19) ENGINE = MyISAM) */
+ PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19) ENGINE = MyISAM,
+ PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29) ENGINE = MyISAM) */
 SELECT * FROM t1;
 a	b
 1	Original from partition p0
@@ -3844,9 +5850,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_6";
-SET SESSION debug="+d,fail_change_partition_7";
+SET SESSION debug="-d,fail_change_partition_9";
+SET SESSION debug="+d,fail_change_partition_10";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -3913,8 +5920,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_7";
-SET SESSION debug="+d,fail_change_partition_8";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -3947,6 +5953,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -3980,9 +5987,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_8";
-SET SESSION debug="+d,fail_change_partition_9";
+SET SESSION debug="-d,fail_change_partition_10";
+SET SESSION debug="+d,fail_change_partition_11";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -4049,8 +6057,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_9";
-SET SESSION debug="+d,fail_change_partition_10";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -4083,6 +6090,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -4116,9 +6124,10 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_10";
-SET SESSION debug="+d,fail_change_partition_11";
+SET SESSION debug="-d,fail_change_partition_11";
+SET SESSION debug="+d,fail_change_partition_12";
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -4185,8 +6194,7 @@ a	b
 3	Original from partition p0
 4	Original from partition p0
 DROP TABLE t1;
-SET SESSION debug="-d,fail_change_partition_11";
-SET SESSION debug="+d,fail_change_partition_12";
+# Same test under LOCK TABLE
 CREATE TABLE t1 (a INT, b VARCHAR(64))
 ENGINE = 'MyISAM'
 PARTITION BY LIST (a)
@@ -4219,6 +6227,7 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+LOCK TABLE t1 WRITE;
 ALTER TABLE t1 REORGANIZE PARTITION p10 INTO
 (PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19),
 PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29));
@@ -4252,5 +6261,6 @@ a	b
 2	Original from partition p0
 3	Original from partition p0
 4	Original from partition p0
+UNLOCK TABLES;
 DROP TABLE t1;
 SET SESSION debug="-d,fail_change_partition_12";

=== modified file 'mysql-test/suite/parts/r/partition_special_innodb.result'
--- a/mysql-test/suite/parts/r/partition_special_innodb.result	2010-08-13 07:50:25 +0000
+++ b/mysql-test/suite/parts/r/partition_special_innodb.result	2010-09-21 23:29:26 +0000
@@ -238,11 +238,10 @@ LOCK TABLE t1 READ;
 # Third attempt: says that the table does not exist
 ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
 ERROR HY000: Lock wait timeout exceeded; try restarting transaction
-# Check table returns the same
+# Check table returns the same (not after fixing bug#56172!)
 CHECK TABLE t1;
 Table	Op	Msg_type	Msg_text
-test.t1	check	Error	Lock wait timeout exceeded; try restarting transaction
-test.t1	check	error	Corrupt
+test.t1	check	status	OK
 UNLOCK TABLES;
 DROP TABLE t1;
 CREATE TABLE t2 ( i INT NOT NULL AUTO_INCREMENT PRIMARY KEY, f INT )

=== modified file 'mysql-test/suite/parts/t/partition_debug_innodb-master.opt'
--- a/mysql-test/suite/parts/t/partition_debug_innodb-master.opt	2010-08-13 07:50:25 +0000
+++ b/mysql-test/suite/parts/t/partition_debug_innodb-master.opt	2010-09-21 23:29:26 +0000
@@ -1 +1 @@
---innodb-file-format-check --innodb-file-per-table=1 --skip-stack-trace --skip-core-file
+--innodb-file-format-check --innodb-file-per-table=1

=== removed file 'mysql-test/suite/parts/t/partition_debug_myisam-master.opt'
--- a/mysql-test/suite/parts/t/partition_debug_myisam-master.opt	2010-08-13 07:50:25 +0000
+++ b/mysql-test/suite/parts/t/partition_debug_myisam-master.opt	1970-01-01 00:00:00 +0000
@@ -1 +0,0 @@
---skip-stack-trace --skip-core-file

=== modified file 'mysql-test/suite/parts/t/partition_special_innodb.test'
--- a/mysql-test/suite/parts/t/partition_special_innodb.test	2010-08-13 07:50:25 +0000
+++ b/mysql-test/suite/parts/t/partition_special_innodb.test	2010-09-21 23:29:26 +0000
@@ -111,7 +111,7 @@ LOCK TABLE t1 READ;
 --echo # Third attempt: says that the table does not exist
 --error ER_LOCK_WAIT_TIMEOUT
 ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
---echo # Check table returns the same
+--echo # Check table returns the same (not after fixing bug#56172!)
 CHECK TABLE t1;
 
 --connection con1

=== modified file 'sql/sql_partition.cc'
--- a/sql/sql_partition.cc	2010-08-20 17:15:48 +0000
+++ b/sql/sql_partition.cc	2010-09-21 23:29:26 +0000
@@ -71,7 +71,7 @@
 #include "ha_partition.h"
 
 #define ERROR_INJECT_CRASH(code) \
-  DBUG_EVALUATE_IF(code, (abort(), 0), 0)
+  DBUG_EVALUATE_IF(code, (_exit(EXIT_FAILURE), 0), 0)
 #define ERROR_INJECT_ERROR(code) \
   DBUG_EVALUATE_IF(code, (my_error(ER_UNKNOWN_ERROR, MYF(0)), TRUE), 0)
 
@@ -4353,15 +4353,15 @@ set_engine_all_partitions(partition_info
     }
   } while (++i < part_info->num_parts);
 }
+
+
 /*
   SYNOPSIS
     fast_end_partition()
     thd                           Thread object
-    out:copied                    Number of records copied
-    out:deleted                   Number of records deleted
+    copied                        Number of records copied
+    deleted                       Number of records deleted
     table_list                    Table list with the one table in it
-    empty                         Has nothing been done
-    lpt                           Struct to be used by error handler
 
   RETURN VALUES
     FALSE                         Success
@@ -4374,22 +4374,14 @@ set_engine_all_partitions(partition_info
 
 static int fast_end_partition(THD *thd, ulonglong copied,
                               ulonglong deleted,
-                              TABLE_LIST *table_list, bool is_empty,
-                              ALTER_PARTITION_PARAM_TYPE *lpt,
-                              bool written_bin_log)
+                              TABLE_LIST *table_list)
 {
   char tmp_name[80];
   DBUG_ENTER("fast_end_partition");
 
   thd->proc_info="end";
 
-  if (!is_empty)
-    query_cache_invalidate3(thd, table_list, 0);
-
-  if ((!is_empty) && (!written_bin_log) &&
-      (!thd->lex->no_write_to_binlog) &&
-    write_bin_log(thd, FALSE, thd->query(), thd->query_length()))
-    DBUG_RETURN(TRUE);
+  query_cache_invalidate3(thd, table_list, 0);
 
   my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
               (ulong) (copied + deleted),
@@ -4522,14 +4514,14 @@ uint set_part_state(Alter_info *alter_in
     inout:create_info          Create info for CREATE TABLE
     old_db_type                Old engine type
     out:partition_changed      Boolean indicating whether partition changed
-    out:fast_alter_partition   Boolean indicating whether fast partition
-                               change is requested
+    out:fast_alter_table       Internal temporary table allowing fast partition
+                               change or NULL if not possible.
 
   RETURN VALUES
     TRUE                       Error
     FALSE                      Success
     partition_changed
-    fast_alter_partition
+    fast_alter_table
 
   DESCRIPTION
     This method handles all preparations for ALTER TABLE for partitioned
@@ -4545,8 +4537,12 @@ uint prep_alter_part_table(THD *thd, TAB
                            HA_CREATE_INFO *create_info,
                            handlerton *old_db_type,
                            bool *partition_changed,
-                           uint *fast_alter_partition)
+                           char *db,
+                           const char *table_name,
+                           const char *path,
+                           TABLE **fast_alter_table)
 {
+  TABLE *new_table= NULL;
   DBUG_ENTER("prep_alter_part_table");
 
   /* Foreign keys on partitioned tables are not supported, waits for WL#148 */
@@ -4555,15 +4551,9 @@ uint prep_alter_part_table(THD *thd, TAB
     my_error(ER_FOREIGN_KEY_ON_PARTITIONED, MYF(0));
     DBUG_RETURN(TRUE);
   }
-  /*
-    We are going to manipulate the partition info on the table object
-    so we need to ensure that the table instance is removed from the
-    table cache.
-  */
-  if (table->part_info)
-    table->m_needs_reopen= TRUE;
 
   thd->work_part_info= thd->lex->part_info;
+
   if (thd->work_part_info &&
       !(thd->work_part_info= thd->lex->part_info->get_clone()))
     DBUG_RETURN(TRUE);
@@ -4576,7 +4566,7 @@ uint prep_alter_part_table(THD *thd, TAB
        ALTER_COALESCE_PARTITION | ALTER_REORGANIZE_PARTITION |
        ALTER_TABLE_REORG | ALTER_REBUILD_PARTITION))
   {
-    partition_info *tab_part_info= table->part_info;
+    partition_info *tab_part_info;
     partition_info *alt_part_info= thd->work_part_info;
     uint flags= 0;
     bool is_last_partition_reorged= FALSE;
@@ -4584,11 +4574,28 @@ uint prep_alter_part_table(THD *thd, TAB
     part_elem_value *alt_max_elem_val= NULL;
     longlong tab_max_range= 0, alt_max_range= 0;
 
-    if (!tab_part_info)
+    if (!table->part_info)
     {
       my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0));
       DBUG_RETURN(TRUE);
     }
+
+    /*
+      Open our intermediate table, we will operate on a temporary instance
+      original table, to be able to skip copying all partitions.
+    */
+    new_table= open_temporary_table(thd, path, db, table_name, 1);
+    if (!new_table)
+      DBUG_RETURN(TRUE);
+
+    /*
+      This table may be used for copy rows between partitions
+      and also read/write columns when fixing the partition_info struct.
+    */
+    new_table->use_all_columns();
+ 
+    tab_part_info= new_table->part_info;
+
     if (alter_info->flags & ALTER_TABLE_REORG)
     {
       uint new_part_no, curr_part_no;
@@ -4596,9 +4603,9 @@ uint prep_alter_part_table(THD *thd, TAB
           tab_part_info->use_default_num_partitions)
       {
         my_error(ER_REORG_NO_PARAM_ERROR, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
-      new_part_no= table->file->get_default_no_partitions(create_info);
+      new_part_no= new_table->file->get_default_no_partitions(create_info);
       curr_part_no= tab_part_info->num_parts;
       if (new_part_no == curr_part_no)
       {
@@ -4607,7 +4614,8 @@ uint prep_alter_part_table(THD *thd, TAB
           after the change as before. Thus we can reply ok immediately
           without any changes at all.
         */
-        *fast_alter_partition= TRUE;
+        *fast_alter_table= new_table;
+        thd->work_part_info= tab_part_info;
         DBUG_RETURN(FALSE);
       }
       else if (new_part_no > curr_part_no)
@@ -4629,15 +4637,15 @@ uint prep_alter_part_table(THD *thd, TAB
         alter_info->num_parts= curr_part_no - new_part_no;
       }
     }
-    if (!(flags= table->file->alter_table_flags(alter_info->flags)))
+    if (!(flags= new_table->file->alter_table_flags(alter_info->flags)))
     {
       my_error(ER_PARTITION_FUNCTION_FAILURE, MYF(0));
-      DBUG_RETURN(1);
+      goto err;
     }
-    *fast_alter_partition=
-      ((flags & (HA_FAST_CHANGE_PARTITION | HA_PARTITION_ONE_PHASE)) != 0);
-    DBUG_PRINT("info", ("*fast_alter_partition: %d  flags: 0x%x",
-                        *fast_alter_partition, flags));
+    if ((flags & (HA_FAST_CHANGE_PARTITION | HA_PARTITION_ONE_PHASE)) != 0)
+      *fast_alter_table= new_table;
+    DBUG_PRINT("info", ("*fast_alter_table: %p  flags: 0x%x",
+                        *fast_alter_table, flags));
     if ((alter_info->flags & ALTER_ADD_PARTITION) ||
          (alter_info->flags & ALTER_REORGANIZE_PARTITION))
     {
@@ -4648,12 +4656,12 @@ uint prep_alter_part_table(THD *thd, TAB
           if (tab_part_info->part_type == RANGE_PARTITION)
           {
             my_error(ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0), "RANGE");
-            DBUG_RETURN(TRUE);
+            goto err;
           }
           else if (tab_part_info->part_type == LIST_PARTITION)
           {
             my_error(ER_PARTITIONS_MUST_BE_DEFINED_ERROR, MYF(0), "LIST");
-            DBUG_RETURN(TRUE);
+            goto err;
           }
           /*
             Hash partitions can be altered without parser finds out about
@@ -4684,7 +4692,7 @@ uint prep_alter_part_table(THD *thd, TAB
             my_error(ER_PARTITION_REQUIRES_VALUES_ERROR, MYF(0),
                      "LIST", "IN");
           }
-          DBUG_RETURN(TRUE);
+          goto err;
         }
       }
       if ((tab_part_info->column_list &&
@@ -4698,12 +4706,12 @@ uint prep_alter_part_table(THD *thd, TAB
             alt_part_info->num_columns != 0))
       {
         my_error(ER_PARTITION_COLUMN_LIST_ERROR, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       alt_part_info->column_list= tab_part_info->column_list;
       if (alt_part_info->fix_parser_data(thd))
       {
-        DBUG_RETURN(TRUE);
+        goto err;
       }
     }
     if (alter_info->flags & ALTER_ADD_PARTITION)
@@ -4726,17 +4734,17 @@ uint prep_alter_part_table(THD *thd, TAB
           tab_part_info->part_type != HASH_PARTITION)
       {
         my_error(ER_NO_BINLOG_ERROR, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       if (tab_part_info->defined_max_value)
       {
         my_error(ER_PARTITION_MAXVALUE_ERROR, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       if (num_new_partitions == 0)
       {
         my_error(ER_ADD_PARTITION_NO_NEW_PARTITION, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       if (tab_part_info->is_sub_partitioned())
       {
@@ -4745,7 +4753,7 @@ uint prep_alter_part_table(THD *thd, TAB
         else if (alt_part_info->num_subparts != tab_part_info->num_subparts)
         {
           my_error(ER_ADD_PARTITION_SUBPART_ERROR, MYF(0));
-          DBUG_RETURN(TRUE);
+          goto err;
         }
         check_total_partitions= new_total_partitions*
                                 alt_part_info->num_subparts;
@@ -4753,15 +4761,15 @@ uint prep_alter_part_table(THD *thd, TAB
       if (check_total_partitions > MAX_PARTITIONS)
       {
         my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       alt_part_info->part_type= tab_part_info->part_type;
       alt_part_info->subpart_type= tab_part_info->subpart_type;
-      if (alt_part_info->set_up_defaults_for_partitioning(table->file,
+      if (alt_part_info->set_up_defaults_for_partitioning(new_table->file,
                                                     ULL(0), 
                                                     tab_part_info->num_parts))
       {
-        DBUG_RETURN(TRUE);
+        goto err;
       }
 /*
 Handling of on-line cases:
@@ -4825,7 +4833,7 @@ adding and copying partitions, the secon
 and copying and finally the third line after also dropping the partitions
 that are reorganised.
 */
-      if (*fast_alter_partition &&
+      if (*fast_alter_table &&
           tab_part_info->part_type == HASH_PARTITION)
       {
         uint part_no= 0, start_part= 1, start_sec_part= 1;
@@ -4930,12 +4938,12 @@ that are reorganised.
         do
         {
           partition_element *part_elem= alt_it++;
-          if (*fast_alter_partition)
+          if (*fast_alter_table)
             part_elem->part_state= PART_TO_BE_ADDED;
           if (tab_part_info->partitions.push_back(part_elem))
           {
             mem_alloc_error(1);
-            DBUG_RETURN(TRUE);
+            goto err;
           }
         } while (++part_count < num_new_partitions);
         tab_part_info->num_parts+= num_new_partitions;
@@ -4976,12 +4984,12 @@ that are reorganised.
             tab_part_info->part_type == LIST_PARTITION))
       {
         my_error(ER_ONLY_ON_RANGE_LIST_PARTITION, MYF(0), "DROP");
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       if (num_parts_dropped >= tab_part_info->num_parts)
       {
         my_error(ER_DROP_LAST_PARTITION, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       do
       {
@@ -4999,12 +5007,12 @@ that are reorganised.
       if (num_parts_found != num_parts_dropped)
       {
         my_error(ER_DROP_PARTITION_NON_EXISTENT, MYF(0), "DROP");
-        DBUG_RETURN(TRUE);
+        goto err;
       }
-      if (table->file->is_fk_defined_on_table_or_index(MAX_KEY))
+      if (new_table->file->is_fk_defined_on_table_or_index(MAX_KEY))
       {
         my_error(ER_ROW_IS_REFERENCED, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       tab_part_info->num_parts-= num_parts_dropped;
     }
@@ -5017,12 +5025,12 @@ that are reorganised.
           (!(alter_info->flags & ALTER_ALL_PARTITION)))
       {
         my_error(ER_DROP_PARTITION_NON_EXISTENT, MYF(0), "REBUILD");
-        DBUG_RETURN(TRUE);
+        goto err;
       }
-      if (!(*fast_alter_partition))
+      if (!(*fast_alter_table))
       {
-        table->file->print_error(HA_ERR_WRONG_COMMAND, MYF(0));
-        DBUG_RETURN(TRUE);
+        new_table->file->print_error(HA_ERR_WRONG_COMMAND, MYF(0));
+        goto err;
       }
     }
     else if (alter_info->flags & ALTER_COALESCE_PARTITION)
@@ -5033,17 +5041,17 @@ that are reorganised.
       if (tab_part_info->part_type != HASH_PARTITION)
       {
         my_error(ER_COALESCE_ONLY_ON_HASH_PARTITION, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       if (num_parts_coalesced == 0)
       {
         my_error(ER_COALESCE_PARTITION_NO_PARTITION, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       if (num_parts_coalesced >= tab_part_info->num_parts)
       {
         my_error(ER_DROP_LAST_PARTITION, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
 /*
 Online handling:
@@ -5082,7 +5090,7 @@ state of p1.
         uint part_count= 0, start_part= 1, start_sec_part= 1;
         uint end_part= 0, end_sec_part= 0;
         bool all_parts= TRUE;
-        if (*fast_alter_partition &&
+        if (*fast_alter_table &&
             tab_part_info->linear_hash_ind)
         {
           uint upper_2n= tab_part_info->linear_hash_mask + 1;
@@ -5108,14 +5116,14 @@ state of p1.
         do
         {
           partition_element *p_elem= part_it++;
-          if (*fast_alter_partition &&
+          if (*fast_alter_table &&
               (all_parts ||
               (part_count >= start_part && part_count <= end_part) ||
               (part_count >= start_sec_part && part_count <= end_sec_part)))
             p_elem->part_state= PART_CHANGED;
           if (++part_count > num_parts_remain)
           {
-            if (*fast_alter_partition)
+            if (*fast_alter_table)
               p_elem->part_state= PART_REORGED_DROPPED;
             else
               part_it.remove();
@@ -5150,38 +5158,38 @@ state of p1.
       if (num_parts_reorged > tab_part_info->num_parts)
       {
         my_error(ER_REORG_PARTITION_NOT_EXIST, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       if (!(tab_part_info->part_type == RANGE_PARTITION ||
             tab_part_info->part_type == LIST_PARTITION) &&
            (num_parts_new != num_parts_reorged))
       {
         my_error(ER_REORG_HASH_ONLY_ON_SAME_NO, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       if (tab_part_info->is_sub_partitioned() &&
           alt_part_info->num_subparts &&
           alt_part_info->num_subparts != tab_part_info->num_subparts)
       {
         my_error(ER_PARTITION_WRONG_NO_SUBPART_ERROR, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       check_total_partitions= tab_part_info->num_parts + num_parts_new;
       check_total_partitions-= num_parts_reorged;
       if (check_total_partitions > MAX_PARTITIONS)
       {
         my_error(ER_TOO_MANY_PARTITIONS_ERROR, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       alt_part_info->part_type= tab_part_info->part_type;
       alt_part_info->subpart_type= tab_part_info->subpart_type;
       alt_part_info->num_subparts= tab_part_info->num_subparts;
       DBUG_ASSERT(!alt_part_info->use_default_partitions);
-      if (alt_part_info->set_up_defaults_for_partitioning(table->file,
+      if (alt_part_info->set_up_defaults_for_partitioning(new_table->file,
                                                           ULL(0), 
                                                           0))
       {
-        DBUG_RETURN(TRUE);
+        goto err;
       }
 /*
 Online handling:
@@ -5240,13 +5248,13 @@ the generated partition syntax in a corr
             }
             else
               tab_max_range= part_elem->range_value;
-            if (*fast_alter_partition &&
+            if (*fast_alter_table &&
                 tab_part_info->temp_partitions.push_back(part_elem))
             {
               mem_alloc_error(1);
-              DBUG_RETURN(TRUE);
+              goto err;
             }
-            if (*fast_alter_partition)
+            if (*fast_alter_table)
               part_elem->part_state= PART_TO_BE_REORGED;
             if (!found_first)
             {
@@ -5266,7 +5274,7 @@ the generated partition syntax in a corr
                 else
                   alt_max_range= alt_part_elem->range_value;
 
-                if (*fast_alter_partition)
+                if (*fast_alter_table)
                   alt_part_elem->part_state= PART_TO_BE_ADDED;
                 if (alt_part_count == 0)
                   tab_it.replace(alt_part_elem);
@@ -5277,7 +5285,7 @@ the generated partition syntax in a corr
             else if (found_last)
             {
               my_error(ER_CONSECUTIVE_REORG_PARTITIONS, MYF(0));
-              DBUG_RETURN(TRUE);
+              goto err;
             }
             else
               tab_it.remove();
@@ -5291,7 +5299,7 @@ the generated partition syntax in a corr
         if (drop_count != num_parts_reorged)
         {
           my_error(ER_DROP_PARTITION_NON_EXISTENT, MYF(0), "REORGANIZE");
-          DBUG_RETURN(TRUE);
+          goto err;
         }
         tab_part_info->num_parts= check_total_partitions;
       }
@@ -5312,9 +5320,9 @@ the generated partition syntax in a corr
         tab_part_info->use_default_num_subpartitions= FALSE;
       }
       if (tab_part_info->check_partition_info(thd, (handlerton**)NULL,
-                                              table->file, ULL(0), TRUE))
+                                              new_table->file, ULL(0), TRUE))
       {
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       /*
         The check below needs to be performed after check_partition_info
@@ -5346,7 +5354,7 @@ the generated partition syntax in a corr
           to create "holes".
         */
         my_error(ER_REORG_OUTSIDE_RANGE, MYF(0));
-        DBUG_RETURN(TRUE);
+        goto err;
       }
     }
   }
@@ -5463,7 +5471,7 @@ the generated partition syntax in a corr
         *partition_changed= TRUE;
         if (thd->work_part_info->fix_parser_data(thd))
         {
-          DBUG_RETURN(TRUE);
+          goto err;
         }
       }
       /*
@@ -5484,7 +5492,7 @@ the generated partition syntax in a corr
       if (check_native_partitioned(create_info, &is_native_partitioned,
                                    part_info, thd))
       {
-        DBUG_RETURN(TRUE);
+        goto err;
       }
       if (!is_native_partitioned)
       {
@@ -5494,6 +5502,11 @@ the generated partition syntax in a corr
     }
   }
   DBUG_RETURN(FALSE);
+err:
+  if (new_table)
+    close_temporary_table(thd, new_table, 1, 0);
+  *fast_alter_table= NULL;
+  DBUG_RETURN(TRUE);
 }
 
 
@@ -5536,6 +5549,9 @@ static bool mysql_change_partitions(ALTE
   if(mysql_trans_prepare_alter_copy_data(thd))
     DBUG_RETURN(TRUE);
 
+  if ((error= file->ha_external_lock(thd, F_WRLCK)))
+    DBUG_RETURN(TRUE);
+
   if ((error= file->ha_change_partitions(lpt->create_info, path, &lpt->copied,
                                          &lpt->deleted, lpt->pack_frm_data,
                                          lpt->pack_frm_len)))
@@ -5544,7 +5560,10 @@ static bool mysql_change_partitions(ALTE
   }
 
   if (mysql_trans_commit_alter_copy_data(thd))
-    DBUG_RETURN(TRUE);                      /* The error has been reported */
+    error= 1;                                /* The error has been reported */
+
+  if ((error= file->ha_external_lock(thd, F_UNLCK)))
+    error= 1;
 
   DBUG_RETURN(test(error));
 }
@@ -6294,8 +6313,11 @@ static void alter_partition_lock_handlin
 {
   THD *thd= lpt->thd;
 
-  close_all_tables_for_name(thd, lpt->table->s, FALSE);
+  if (lpt->old_table)
+    close_all_tables_for_name(thd, lpt->old_table->s, FALSE);
+  close_temporary_table(thd, lpt->table, 1, 0);
   lpt->table= 0;
+  lpt->old_table= 0;
   lpt->table_list->table= 0;
   if (thd->locked_tables_list.reopen_tables(thd))
     sql_print_warning("We failed to reacquire LOCKs in ALTER TABLE");
@@ -6307,46 +6329,24 @@ static void alter_partition_lock_handlin
   SYNOPSIS
     alter_close_tables()
     lpt                        Struct carrying parameters
+    close_old                  Close original table too
   RETURN VALUES
     0
 */
 
-static int alter_close_tables(ALTER_PARTITION_PARAM_TYPE *lpt)
+static int alter_close_tables(ALTER_PARTITION_PARAM_TYPE *lpt, bool close_old)
 {
-  TABLE_SHARE *share= lpt->table->s;
-  THD *thd= lpt->thd;
-  TABLE *table;
   DBUG_ENTER("alter_close_tables");
-  /*
-    We must keep LOCK_open while manipulating with thd->open_tables.
-    Another thread may be working on it.
-  */
-  mysql_mutex_lock(&LOCK_open);
-  /*
-    We can safely remove locks for all tables with the same name:
-    later they will all be closed anyway in
-    alter_partition_lock_handling().
-  */
-  for (table= thd->open_tables; table ; table= table->next)
+  if (lpt->table->db_stat)
   {
-    if (!strcmp(table->s->table_name.str, share->table_name.str) &&
-	!strcmp(table->s->db.str, share->db.str))
-    {
-      mysql_lock_remove(thd, thd->lock, table);
-      table->file->close();
-      table->db_stat= 0;                        // Mark file closed
-      /*
-        Ensure that we won't end up with a crippled table instance
-        in the table cache if an error occurs before we reach
-        alter_partition_lock_handling() and the table is closed
-        by close_thread_tables() instead.
-      */
-      tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED,
-                       table->s->db.str,
-                       table->s->table_name.str, TRUE);
-    }
+    lpt->table->file->close();
+    lpt->table->db_stat= 0;                        // Mark file closed
+  }
+  if (close_old && lpt->old_table)
+  {
+    close_all_tables_for_name(lpt->thd, lpt->old_table->s, FALSE);
+    lpt->old_table= 0;
   }
-  mysql_mutex_unlock(&LOCK_open);
   DBUG_RETURN(0);
 }
 
@@ -6356,13 +6356,16 @@ static int alter_close_tables(ALTER_PART
   SYNOPSIS
     handle_alter_part_error()
     lpt                        Struct carrying parameters
-    not_completed              Was request in complete phase when error occurred
+    action_completed           The action must be completed, NOT reverted.
+    drop_partition             Partitions has not been dropped yet.
+    frm_install                The shadow frm-file has not yet been installed.
+    close_table                Table is still open, close it before reverting.
   RETURN VALUES
     NONE
 */
 
 void handle_alter_part_error(ALTER_PARTITION_PARAM_TYPE *lpt,
-                             bool not_completed,
+                             bool action_completed,
                              bool drop_partition,
                              bool frm_install,
                              bool close_table)
@@ -6379,7 +6382,7 @@ void handle_alter_part_error(ALTER_PARTI
       so we clone it first to have a copy.
     */
     part_info= lpt->part_info->get_clone();
-    alter_close_tables(lpt);
+    alter_close_tables(lpt, action_completed);
   }
 
   if (part_info->first_log_entry &&
@@ -6392,7 +6395,7 @@ void handle_alter_part_error(ALTER_PARTI
     */
     write_log_completed(lpt, FALSE);
     release_log_entries(part_info);
-    if (not_completed)
+    if (!action_completed)
     {
       if (drop_partition)
       {
@@ -6457,7 +6460,7 @@ void handle_alter_part_error(ALTER_PARTI
   else
   {
     release_log_entries(part_info);
-    if (not_completed)
+    if (!action_completed)
     {
       /*
         We hit an error before things were completed but managed
@@ -6507,12 +6510,13 @@ static void downgrade_mdl_if_lock_tables
   SYNOPSIS
     fast_alter_partition_table()
     thd                           Thread object
-    table                         Table object
+    table                         Original table object
     alter_info                    ALTER TABLE info
     create_info                   Create info for CREATE TABLE
     table_list                    List of the table involved
     db                            Database name of new table
     table_name                    Table name of new table
+    fast_alter_table              Prepared table object
 
   RETURN VALUES
     TRUE                          Error
@@ -6529,19 +6533,20 @@ uint fast_alter_partition_table(THD *thd
                                 TABLE_LIST *table_list,
                                 char *db,
                                 const char *table_name,
-                                uint fast_alter_partition)
+                                TABLE *fast_alter_table)
 {
   /* Set-up struct used to write frm files */
-  partition_info *part_info= table->part_info;
+  partition_info *part_info;
   ALTER_PARTITION_PARAM_TYPE lpt_obj;
   ALTER_PARTITION_PARAM_TYPE *lpt= &lpt_obj;
-  bool written_bin_log= TRUE;
-  bool not_completed= TRUE;
+  bool action_completed= FALSE;
   bool close_table_on_failure= FALSE;
   bool frm_install= FALSE;
   MDL_ticket *mdl_ticket= table->mdl_ticket;
+  DBUG_ASSERT(fast_alter_table);
   DBUG_ENTER("fast_alter_partition_table");
 
+  part_info= fast_alter_table->part_info;
   lpt->thd= thd;
   lpt->table_list= table_list;
   lpt->part_info= part_info;
@@ -6550,7 +6555,8 @@ uint fast_alter_partition_table(THD *thd
   lpt->db_options= create_info->table_options;
   if (create_info->row_type == ROW_TYPE_DYNAMIC)
     lpt->db_options|= HA_OPTION_PACK_RECORD;
-  lpt->table= table;
+  lpt->table= fast_alter_table;
+  lpt->old_table= table;
   lpt->key_info_buffer= 0;
   lpt->key_count= 0;
   lpt->db= db;
@@ -6559,12 +6565,12 @@ uint fast_alter_partition_table(THD *thd
   lpt->deleted= 0;
   lpt->pack_frm_data= NULL;
   lpt->pack_frm_len= 0;
-  thd->work_part_info= part_info;
 
   /* Never update timestamp columns when alter */
-  table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
+  lpt->table->timestamp_field_type= TIMESTAMP_NO_AUTO_SET;
 
-  if (fast_alter_partition & HA_PARTITION_ONE_PHASE)
+  if (table->file->alter_table_flags(alter_info->flags) &
+                                                        HA_PARTITION_ONE_PHASE)
   {
     /*
       In the case where the engine supports one phase online partition
@@ -6681,11 +6687,11 @@ uint fast_alter_partition_table(THD *thd
         ERROR_INJECT_ERROR("fail_drop_partition_3") ||
         (close_table_on_failure= TRUE, FALSE) ||
         write_log_drop_partition(lpt) ||
+        (action_completed= TRUE, FALSE) ||
         ERROR_INJECT_CRASH("crash_drop_partition_4") ||
         ERROR_INJECT_ERROR("fail_drop_partition_4") ||
+        alter_close_tables(lpt, action_completed) ||
         (close_table_on_failure= FALSE, FALSE) ||
-        (not_completed= FALSE, FALSE) ||
-        alter_close_tables(lpt) ||
         ERROR_INJECT_CRASH("crash_drop_partition_5") ||
         ERROR_INJECT_ERROR("fail_drop_partition_5") ||
         ((!thd->lex->no_write_to_binlog) &&
@@ -6706,7 +6712,7 @@ uint fast_alter_partition_table(THD *thd
         ERROR_INJECT_ERROR("fail_drop_partition_9") ||
         (alter_partition_lock_handling(lpt), FALSE)) 
     {
-      handle_alter_part_error(lpt, not_completed, TRUE, frm_install,
+      handle_alter_part_error(lpt, action_completed, TRUE, frm_install,
                               close_table_on_failure);
       goto err;
     }
@@ -6761,7 +6767,7 @@ uint fast_alter_partition_table(THD *thd
         ERROR_INJECT_CRASH("crash_add_partition_5") ||
         ERROR_INJECT_ERROR("fail_add_partition_5") ||
         (close_table_on_failure= FALSE, FALSE) ||
-        alter_close_tables(lpt) ||
+        alter_close_tables(lpt, action_completed) ||
         ERROR_INJECT_CRASH("crash_add_partition_6") ||
         ERROR_INJECT_ERROR("fail_add_partition_6") ||
         ((!thd->lex->no_write_to_binlog) &&
@@ -6770,11 +6776,12 @@ uint fast_alter_partition_table(THD *thd
         ERROR_INJECT_CRASH("crash_add_partition_7") ||
         ERROR_INJECT_ERROR("fail_add_partition_7") ||
         write_log_rename_frm(lpt) ||
-        (frm_install= TRUE, FALSE) ||
-        (not_completed= FALSE, FALSE) ||
+        (action_completed= TRUE, FALSE) ||
         ERROR_INJECT_CRASH("crash_add_partition_8") ||
         ERROR_INJECT_ERROR("fail_add_partition_8") ||
+        (frm_install= TRUE, FALSE) ||
         mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) ||
+        (frm_install= FALSE, FALSE) ||
         ERROR_INJECT_CRASH("crash_add_partition_9") ||
         ERROR_INJECT_ERROR("fail_add_partition_9") ||
         (write_log_completed(lpt, FALSE), FALSE) ||
@@ -6782,7 +6789,7 @@ uint fast_alter_partition_table(THD *thd
         ERROR_INJECT_ERROR("fail_add_partition_10") ||
         (alter_partition_lock_handling(lpt), FALSE))
     {
-      handle_alter_part_error(lpt, not_completed, FALSE, frm_install,
+      handle_alter_part_error(lpt, action_completed, FALSE, frm_install,
                               close_table_on_failure);
       goto err;
     }
@@ -6831,10 +6838,10 @@ uint fast_alter_partition_table(THD *thd
          can release all other locks on the table and since no one can open
          the table, there can be no new threads accessing the table. They
          will be hanging on this exclusive lock.
-      5) Close all instances of the table and remove them from the table cache.
-      6) Log that operation is completed and log all complete actions
+      5) Log that operation is completed and log all complete actions
          needed to complete operation from here
-      7) Write bin log
+      6) Write bin log
+      7) Close all instances of the table and remove them from the table cache.
       8) Prepare handlers for rename and delete of partitions
       9) Rename and drop the reorged partitions such that they are no
          longer used and rename those added to their real new names.
@@ -6858,27 +6865,28 @@ uint fast_alter_partition_table(THD *thd
         wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN) ||
         ERROR_INJECT_CRASH("crash_change_partition_5") ||
         ERROR_INJECT_ERROR("fail_change_partition_5") ||
-        alter_close_tables(lpt) ||
-        (close_table_on_failure= FALSE) ||
+        write_log_final_change_partition(lpt) ||
+        (action_completed= TRUE, FALSE) ||
         ERROR_INJECT_CRASH("crash_change_partition_6") ||
         ERROR_INJECT_ERROR("fail_change_partition_6") ||
-        write_log_final_change_partition(lpt) ||
-        (not_completed= FALSE) ||
-        ERROR_INJECT_CRASH("crash_change_partition_7") ||
-        ERROR_INJECT_ERROR("fail_change_partition_7") ||
         ((!thd->lex->no_write_to_binlog) &&
          (write_bin_log(thd, FALSE,
                         thd->query(), thd->query_length()), FALSE)) ||
+        ERROR_INJECT_CRASH("crash_change_partition_7") ||
+        ERROR_INJECT_ERROR("fail_change_partition_7") ||
+        ((frm_install= TRUE), FALSE) ||
+        mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) ||
+        (frm_install= FALSE, FALSE) ||
         ERROR_INJECT_CRASH("crash_change_partition_8") ||
         ERROR_INJECT_ERROR("fail_change_partition_8") ||
-        mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) ||
+        alter_close_tables(lpt, action_completed) ||
+        (close_table_on_failure= FALSE, FALSE) ||
         ERROR_INJECT_CRASH("crash_change_partition_9") ||
         ERROR_INJECT_ERROR("fail_change_partition_9") ||
         mysql_drop_partitions(lpt) ||
         ERROR_INJECT_CRASH("crash_change_partition_10") ||
         ERROR_INJECT_ERROR("fail_change_partition_10") ||
         mysql_rename_partitions(lpt) ||
-        ((frm_install= TRUE), FALSE) ||
         ERROR_INJECT_CRASH("crash_change_partition_11") ||
         ERROR_INJECT_ERROR("fail_change_partition_11") ||
         (write_log_completed(lpt, FALSE), FALSE) ||
@@ -6886,7 +6894,7 @@ uint fast_alter_partition_table(THD *thd
         ERROR_INJECT_ERROR("fail_change_partition_12") ||
         (alter_partition_lock_handling(lpt), FALSE))
     {
-      handle_alter_part_error(lpt, not_completed, FALSE, frm_install,
+      handle_alter_part_error(lpt, action_completed, FALSE, frm_install,
                               close_table_on_failure);
       goto err;
     }
@@ -6896,12 +6904,25 @@ uint fast_alter_partition_table(THD *thd
     A final step is to write the query to the binlog and send ok to the
     user
   */
-  DBUG_RETURN(fast_end_partition(thd, lpt->copied, lpt->deleted,
-                                 table_list, FALSE, NULL,
-                                 written_bin_log));
+  DBUG_RETURN(fast_end_partition(thd, lpt->copied, lpt->deleted, table_list));
 err:
+  if (action_completed)
+  {
+    /*
+      Although error occurred, the action was forced to retry for completion.
+      Therefore we must close+reopen all instances of the table.
+    */
+    (void) alter_partition_lock_handling(lpt);
+  }
+  else
+  {
+    /*
+      The failed action was reverted, leave the original table as is and
+      close/destroy the intermediate table.
+    */
+    close_temporary_table(thd, lpt->table, 1, 0);
+  }
   downgrade_mdl_if_lock_tables_mode(thd, mdl_ticket, MDL_SHARED_NO_READ_WRITE);
-  table->m_needs_reopen= TRUE;
   DBUG_RETURN(TRUE);
 }
 #endif

=== modified file 'sql/sql_partition.h'
--- a/sql/sql_partition.h	2010-07-29 03:24:35 +0000
+++ b/sql/sql_partition.h	2010-09-21 23:29:26 +0000
@@ -54,6 +54,7 @@ typedef struct st_lock_param_type
   HA_CREATE_INFO *create_info;
   Alter_info *alter_info;
   TABLE *table;
+  TABLE *old_table;
   KEY *key_info_buffer;
   const char *db;
   const char *table_name;
@@ -252,14 +253,17 @@ uint fast_alter_partition_table(THD *thd
                                 TABLE_LIST *table_list,
                                 char *db,
                                 const char *table_name,
-                                uint fast_alter_partition);
+                                TABLE  *fast_alter_table);
 uint set_part_state(Alter_info *alter_info, partition_info *tab_part_info,
                     enum partition_state part_state);
 uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
                            HA_CREATE_INFO *create_info,
                            handlerton *old_db_type,
                            bool *partition_changed,
-                           uint *fast_alter_partition);
+                           char *db,
+                           const char *table_name,
+                           const char *path,
+                           TABLE **fast_alter_table);
 char *generate_partition_syntax(partition_info *part_info,
                                 uint *buf_length, bool use_sql_alloc,
                                 bool show_partition_options,

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2010-08-25 10:22:34 +0000
+++ b/sql/sql_table.cc	2010-09-21 23:29:26 +0000
@@ -1725,8 +1725,6 @@ bool mysql_write_frm(ALTER_PARTITION_PAR
                                                   CHF_DELETE_FLAG, NULL) ||
         deactivate_ddl_log_entry(part_info->frm_log_entry->entry_pos) ||
         (sync_ddl_log(), FALSE) ||
-#endif
-#ifdef WITH_PARTITION_STORAGE_ENGINE
         mysql_file_rename(key_file_frm,
                           shadow_frm_name, frm_name, MYF(MY_WME)) ||
         lpt->table->file->ha_create_handler_files(path, shadow_path,
@@ -5599,7 +5597,7 @@ bool mysql_alter_table(THD *thd,char *ne
   handlerton *old_db_type, *new_db_type, *save_old_db_type;
   enum_alter_table_change_level need_copy_table= ALTER_TABLE_METADATA_ONLY;
 #ifdef WITH_PARTITION_STORAGE_ENGINE
-  uint fast_alter_partition= 0;
+  TABLE *table_for_fast_alter_partition= NULL;
   bool partition_changed= FALSE;
 #endif
   bool need_lock_for_indexes= TRUE;
@@ -5968,7 +5966,9 @@ bool mysql_alter_table(THD *thd,char *ne
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   if (prep_alter_part_table(thd, table, alter_info, create_info, old_db_type,
-                            &partition_changed, &fast_alter_partition))
+                            &partition_changed,
+                            db, table_name, path,
+                            &table_for_fast_alter_partition))
     goto err;
 #endif
   /*
@@ -6201,12 +6201,12 @@ bool mysql_alter_table(THD *thd,char *ne
     create_info->frm_only= 1;
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
-  if (fast_alter_partition)
+  if (table_for_fast_alter_partition)
   {
     DBUG_RETURN(fast_alter_partition_table(thd, table, alter_info,
                                            create_info, table_list,
                                            db, table_name,
-                                           fast_alter_partition));
+                                           table_for_fast_alter_partition));
   }
 #endif
 
@@ -6686,6 +6686,10 @@ err_new_table_cleanup:
                           create_info->frm_only ? FN_IS_TMP | FRM_ONLY : FN_IS_TMP);
 
 err:
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+  if (table_for_fast_alter_partition)
+    close_temporary_table(thd, table_for_fast_alter_partition, 1, 0);
+#endif /* WITH_PARTITION_STORAGE_ENGINE */
   /*
     No default value was provided for a DATE/DATETIME field, the
     current sql_mode doesn't allow the '0000-00-00' value and


Attachment: [text/bzr-bundle] bzr/mattias.jonsson@oracle.com-20100921232926-jm1pk1ukoequ1jhd.bundle
Thread
bzr commit into mysql-5.5-bugfixing branch (mattias.jonsson:3210) Bug#56172Mattias Jonsson22 Sep
  • Re: bzr commit into mysql-5.5-bugfixing branch (mattias.jonsson:3210)Bug#56172Davi Arnaut30 Sep