summaryrefslogtreecommitdiff
path: root/mysql-test/suite/parts
diff options
context:
space:
mode:
authorSergey Vojtovich <svoj@mariadb.org>2013-09-27 16:58:49 +0400
committerSergey Vojtovich <svoj@mariadb.org>2013-09-27 16:58:49 +0400
commit47a240c6bc994ddc26ff139050b16649137cb3ce (patch)
treee59a8bf3425542dd1604a5be4487b248af47b747 /mysql-test/suite/parts
parenta695674001c933ff6bf0fdbdf3b05436c50bd5bc (diff)
downloadmariadb-git-47a240c6bc994ddc26ff139050b16649137cb3ce.tar.gz
MDEV-4864 - Merge tests for EXCHANGE PARTITION feature
Diffstat (limited to 'mysql-test/suite/parts')
-rw-r--r--mysql-test/suite/parts/disabled.def3
-rw-r--r--mysql-test/suite/parts/inc/part_exch_drop_tabs.inc15
-rw-r--r--mysql-test/suite/parts/inc/part_exch_qa.inc148
-rw-r--r--mysql-test/suite/parts/inc/part_exch_qa_1.inc62
-rw-r--r--mysql-test/suite/parts/inc/part_exch_qa_13.inc202
-rw-r--r--mysql-test/suite/parts/inc/part_exch_qa_4.inc45
-rw-r--r--mysql-test/suite/parts/inc/part_exch_qa_5.inc89
-rw-r--r--mysql-test/suite/parts/inc/part_exch_qa_7.inc63
-rw-r--r--mysql-test/suite/parts/inc/part_exch_qa_8.inc71
-rw-r--r--mysql-test/suite/parts/inc/part_exch_tabs.inc139
-rw-r--r--mysql-test/suite/parts/inc/partition_exchange.inc361
-rw-r--r--mysql-test/suite/parts/inc/partition_mgm.inc30
-rw-r--r--mysql-test/suite/parts/r/partition_debug.result1932
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_innodb.result355
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_myisam.result355
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_myisam_innodb.result14
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa.result355
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_10.result70
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_11.result56
-rw-r--r--mysql-test/suite/parts/r/partition_exch_qa_12.result123
-rw-r--r--mysql-test/suite/parts/r/partition_exch_qa_13.result203
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_14.result45
-rw-r--r--mysql-test/suite/parts/r/partition_exch_qa_15.result19
-rw-r--r--mysql-test/suite/parts/r/partition_exch_qa_1_innodb.result171
-rw-r--r--mysql-test/suite/parts/r/partition_exch_qa_1_myisam.result171
-rw-r--r--mysql-test/suite/parts/r/partition_exch_qa_2.result138
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_3.result17
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_4_innodb.result76
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_4_myisam.result76
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_5_innodb.result114
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_5_myisam.result114
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_6.result105
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_7_innodb.result82
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_7_myisam.result82
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_8_innodb.result83
-rwxr-xr-xmysql-test/suite/parts/r/partition_exch_qa_8_myisam.result83
-rw-r--r--mysql-test/suite/parts/r/partition_exchange_archive.result322
-rw-r--r--mysql-test/suite/parts/r/partition_exchange_blackhole.result10
-rw-r--r--mysql-test/suite/parts/r/partition_exchange_innodb.result374
-rw-r--r--mysql-test/suite/parts/r/partition_exchange_memory.result374
-rw-r--r--mysql-test/suite/parts/r/partition_exchange_myisam.result374
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc0_archive.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc0_memory.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc1_archive.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc1_memory.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc2_archive.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc2_memory.result72
-rw-r--r--mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result72
-rw-r--r--mysql-test/suite/parts/r/partition_repair_myisam.result61
-rw-r--r--mysql-test/suite/parts/t/partition_debug.test33
-rw-r--r--mysql-test/suite/parts/t/partition_exch_innodb.test12
-rw-r--r--mysql-test/suite/parts/t/partition_exch_myisam.test11
-rw-r--r--mysql-test/suite/parts/t/partition_exch_myisam_innodb.test21
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa.test11
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_10.test69
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_11.test37
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_12.test178
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_13.test11
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_14.test94
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_15.test31
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_1_innodb.test12
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_1_myisam.test11
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_2.test80
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_3.test47
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_4_innodb.test12
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_4_myisam.test11
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_5_innodb.test12
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_5_myisam.test11
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_6.test102
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_7_innodb.test12
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_7_myisam.test11
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_8_innodb.test12
-rw-r--r--mysql-test/suite/parts/t/partition_exch_qa_8_myisam.test11
-rw-r--r--mysql-test/suite/parts/t/partition_exchange_archive.test11
-rw-r--r--mysql-test/suite/parts/t/partition_exchange_blackhole.test18
-rw-r--r--mysql-test/suite/parts/t/partition_exchange_innodb.test6
-rw-r--r--mysql-test/suite/parts/t/partition_exchange_memory.test5
-rw-r--r--mysql-test/suite/parts/t/partition_exchange_myisam.test5
-rw-r--r--mysql-test/suite/parts/t/partition_repair_myisam.test39
84 files changed, 9382 insertions, 0 deletions
diff --git a/mysql-test/suite/parts/disabled.def b/mysql-test/suite/parts/disabled.def
index 96592e78911..b0c2cd0d4ef 100644
--- a/mysql-test/suite/parts/disabled.def
+++ b/mysql-test/suite/parts/disabled.def
@@ -11,3 +11,6 @@
##############################################################################
partition_value_myisam : CAST() in partitioning function is currently not supported
partition_value_innodb : CAST() in partitioning function is currently not supported
+parts.partition_mgm_lc1_archive : MDEV-5077 2013-09-27 svoj Cannot exchange partition with archive table
+parts.partition_exchange_archive: MDEV-5077 2013-09-27 svoj Cannot exchange partition with archive table
+parts.partition_mgm_lc0_archive : MDEV-5077 2013-09-27 svoj Cannot exchange partition with archive table
diff --git a/mysql-test/suite/parts/inc/part_exch_drop_tabs.inc b/mysql-test/suite/parts/inc/part_exch_drop_tabs.inc
new file mode 100644
index 00000000000..5ffc5438a3e
--- /dev/null
+++ b/mysql-test/suite/parts/inc/part_exch_drop_tabs.inc
@@ -0,0 +1,15 @@
+--disable_warnings
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+--enable_warnings
+
diff --git a/mysql-test/suite/parts/inc/part_exch_qa.inc b/mysql-test/suite/parts/inc/part_exch_qa.inc
new file mode 100644
index 00000000000..1f5329a53ab
--- /dev/null
+++ b/mysql-test/suite/parts/inc/part_exch_qa.inc
@@ -0,0 +1,148 @@
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM t_100;
+--sorted_result
+SELECT * FROM t_1000;
+--sorted_result
+SELECT * FROM tp;
+--sorted_result
+SELECT * FROM tsp;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp_01;
+--sorted_result
+SELECT * FROM tsp_02;
+--sorted_result
+SELECT * FROM tsp_03;
+--sorted_result
+SELECT * FROM tsp_04;
+
+# 1) Valid exchange with partitions.
+# exchange of values < 10 of tp to t and complete contents of t to p0 and back.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+# Back to the former contents.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+
+# Exchange with empty table.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty;
+--sorted_result
+SELECT * FROM t_empty;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+# Back to the former contents.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty;
+--sorted_result
+SELECT * FROM t_empty;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+
+# Exchange with null table.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null;
+--sorted_result
+SELECT * FROM t_null;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+# Back to the former contents.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null;
+--sorted_result
+SELECT * FROM t_null;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+
+# exchange of values < 100 of tp to t and complete contents of t to p1 and back.
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+--sorted_result
+SELECT * FROM t_100;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 10 AND 100;
+# Back to the former contents.
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+--sorted_result
+SELECT * FROM t_100;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 10 AND 100;
+
+# exchange of values < 1000 of tp to t and complete contents of t to p2 and back.
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000;
+--sorted_result
+SELECT * FROM t_1000;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 100 AND 1000;
+# Back to the former contents.
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000;
+--sorted_result
+SELECT * FROM t_1000;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 100 AND 1000;
+
+# 2) Valid exchange of subpartitions.
+# exchange of values < 10 of tsp to t and complete contents of t to p0 and back.
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01;
+ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02;
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp_01;
+--sorted_result
+SELECT * FROM tsp_02;
+--sorted_result
+SELECT * FROM tsp_03;
+--sorted_result
+SELECT * FROM tsp_04;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+# Back to the former contents.
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01;
+ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02;
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp_01;
+--sorted_result
+SELECT * FROM tsp_02;
+--sorted_result
+SELECT * FROM tsp_03;
+--sorted_result
+SELECT * FROM tsp_04;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+
+# Exchange with null table.
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null;
+--sorted_result
+SELECT * FROM t_null;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+# Back to the former contents.
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null;
+--sorted_result
+SELECT * FROM t_null;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/inc/part_exch_qa_1.inc b/mysql-test/suite/parts/inc/part_exch_qa_1.inc
new file mode 100644
index 00000000000..d790f29af6c
--- /dev/null
+++ b/mysql-test/suite/parts/inc/part_exch_qa_1.inc
@@ -0,0 +1,62 @@
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM t_100;
+--sorted_result
+SELECT * FROM t_1000;
+--sorted_result
+SELECT * FROM tp;
+--sorted_result
+SELECT * FROM tsp;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp_01;
+--sorted_result
+SELECT * FROM tsp_02;
+--sorted_result
+SELECT * FROM tsp_03;
+--sorted_result
+SELECT * FROM tsp_04;
+
+# 13) Exchanges with indexes.
+# IGNORE was removed in bug#57708.
+CREATE INDEX id_t_10_b USING BTREE ON t_10 (b);
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+#--error ER_TABLES_DIFFERENT_METADATA
+#ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10 IGNORE;
+CREATE INDEX id_tp_b USING BTREE ON tp (b);
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+#--error ER_TABLES_DIFFERENT_METADATA
+#ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10 IGNORE;
+DROP INDEX id_t_10_b ON t_10;
+DROP INDEX id_tp_b ON tp;
+ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a);
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+#--error ER_TABLES_DIFFERENT_METADATA
+#ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10 IGNORE;
+ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+show create table t_10;
+show create table tp ;
+ALTER TABLE tp DROP INDEX a;
+ALTER TABLE t_10 DROP INDEX a;
+ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a,b);
+ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a,b);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+show create table t_10;
+show create table tp ;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/inc/part_exch_qa_13.inc b/mysql-test/suite/parts/inc/part_exch_qa_13.inc
new file mode 100644
index 00000000000..aba75d22b26
--- /dev/null
+++ b/mysql-test/suite/parts/inc/part_exch_qa_13.inc
@@ -0,0 +1,202 @@
+# Author: Horst Hunger
+# Created: 2010-07-13
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--disable_warnings
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+--enable_warnings
+
+eval CREATE TABLE t_10 (a INT, b VARCHAR(55), PRIMARY KEY (a))
+CHECKSUM= 1,
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_100 (a INT, b VARCHAR(55), PRIMARY KEY (a))
+COMMENT= 'comment',
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_1000 (a INT, b VARCHAR(55), PRIMARY KEY (a))
+MIN_ROWS= 1,
+MAX_ROWS= 2000,
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_empty (a INT, b VARCHAR(55), PRIMARY KEY (a))
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_null (a INT, b VARCHAR(55), PRIMARY KEY (a))
+ENGINE = $engine_table;
+
+eval CREATE TABLE tp (a INT, b VARCHAR(55), PRIMARY KEY (a))
+CHECKSUM= 1,
+ENGINE = $engine_part
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+ PARTITION p1 VALUES LESS THAN (100),
+ PARTITION p2 VALUES LESS THAN (1000));
+
+eval CREATE TABLE tp1 (a INT, b VARCHAR(55), PRIMARY KEY (a))
+ENGINE = $engine_part
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) MAX_ROWS=2000 MIN_ROWS=1,
+ PARTITION p1 VALUES LESS THAN (100) MAX_ROWS=2000 MIN_ROWS=1,
+ PARTITION p2 VALUES LESS THAN (1000) MAX_ROWS=2000 MIN_ROWS=1
+);
+
+eval CREATE TABLE tsp (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+COMMENT= 'comment',
+ENGINE = $engine_subpart
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (10)
+ (SUBPARTITION sp00 MAX_ROWS=2000 MIN_ROWS=1,
+ SUBPARTITION sp01 MAX_ROWS=2000 MIN_ROWS=1,
+ SUBPARTITION sp02 MAX_ROWS=2000 MIN_ROWS=1,
+ SUBPARTITION sp03 MAX_ROWS=2000 MIN_ROWS=1,
+ SUBPARTITION sp04 MAX_ROWS=2000 MIN_ROWS=1),
+ PARTITION p1 VALUES LESS THAN (100)
+ (SUBPARTITION sp10,
+ SUBPARTITION sp11,
+ SUBPARTITION sp12,
+ SUBPARTITION sp13,
+ SUBPARTITION sp14),
+ PARTITION p2 VALUES LESS THAN (1000)
+ (SUBPARTITION sp20,
+ SUBPARTITION sp21,
+ SUBPARTITION sp22,
+ SUBPARTITION sp23,
+ SUBPARTITION sp24));
+
+# Values t_10 (not partitioned)
+INSERT INTO t_10 VALUES (1, "One"), (3, "Three"), (5, "Five"), (9, "Nine");
+
+# Values t_100 (not partitioned)
+INSERT INTO t_100 VALUES (11, "Eleven"), (13, "Thirdteen"), (15, "Fifeteen"), (19, "Nineteen");
+INSERT INTO t_100 VALUES (91, "Ninety-one"), (93, "Ninety-three"), (95, "Ninety-five"), (99, "Ninety-nine");
+
+# Values t_1000 (not partitioned)
+INSERT INTO t_1000 VALUES (111, "Hundred elven"), (113, "Hundred thirdteen"), (115, "Hundred fiveteen"), (119, "Hundred nineteen");
+INSERT INTO t_1000 VALUES (131, "Hundred thirty-one"), (133, "Hundred thirty-three"), (135, "Hundred thirty-five"), (139, "Hundred thirty-nine");
+INSERT INTO t_1000 VALUES (151, "Hundred fifty-one"), (153, "Hundred fifty-three"), (155, "Hundred fity-five"), (159, "Hundred fifty-nine");
+INSERT INTO t_1000 VALUES (191, "Hundred ninety-one"), (193, "Hundred ninety-three"), (195, "Hundred ninety-five"), (199, "Hundred ninety-nine");
+
+# Values t_null (not partitioned)
+INSERT INTO t_null VALUES (1, "NULL");
+
+# Values tp (partitions)
+INSERT INTO tp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight");
+INSERT INTO tp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen");
+INSERT INTO tp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen");
+INSERT INTO tp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight");
+INSERT INTO tp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight");
+INSERT INTO tp VALUES (182, "Hundred eighty-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight");
+
+# Values tp1 (partitions)
+INSERT INTO tp1 VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight");
+INSERT INTO tp1 VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen");
+INSERT INTO tp1 VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen");
+INSERT INTO tp1 VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight");
+INSERT INTO tp1 VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight");
+INSERT INTO tp1 VALUES (182, "Hundred eighty-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight");
+
+# Values tps (subpartitions)
+INSERT INTO tsp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight");
+INSERT INTO tsp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen");
+INSERT INTO tsp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen");
+INSERT INTO tsp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight");
+INSERT INTO tsp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight");
+INSERT INTO tsp VALUES (182, "Hundred eight-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight");
+
+eval CREATE TABLE tsp_01(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 1;
+eval CREATE TABLE tsp_02(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 2;
+eval CREATE TABLE tsp_03(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table,
+ MAX_ROWS=2000, MIN_ROWS=1
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 3;
+eval CREATE TABLE tsp_04(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 4;
+eval CREATE TABLE tsp_00(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 0;
+
+SHOW CREATE TABLE t_100;
+SHOW CREATE TABLE t_1000;
+SHOW CREATE TABLE tp;
+SHOW CREATE TABLE tsp;
+
+--enable_result_log
+--enable_query_log
+
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM t_100;
+--sorted_result
+SELECT * FROM t_1000;
+--sorted_result
+SELECT * FROM tp;
+--sorted_result
+SELECT * FROM tsp;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp_01;
+--sorted_result
+SELECT * FROM tsp_02;
+--sorted_result
+SELECT * FROM tsp_03;
+--sorted_result
+SELECT * FROM tsp_04;
+
+# 13) Exchanges with different table options.
+# See bug#55944 to change the IGNORE
+# IGNORE was removed in bug#57708.
+INSERT INTO t_10 VALUES (10, "TEN");
+--error ER_ROW_DOES_NOT_MATCH_PARTITION
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--sorted_result
+SELECT * FROM tp WHERE a < 11;
+--sorted_result
+SELECT * FROM t_10 WHERE a < 11;
+#ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10 IGNORE;
+#--sorted_result
+#SELECT * FROM tp WHERE a < 11;
+#--sorted_result
+#SELECT * FROM t_10 WHERE a < 11;
+INSERT INTO t_1000 VALUES (99, "Ninetynine");
+--error ER_ROW_DOES_NOT_MATCH_PARTITION
+ALTER TABLE tp1 EXCHANGE PARTITION p2 WITH TABLE t_1000;
+--sorted_result
+SELECT * FROM tp1 WHERE a < 1000 AND a > 98;
+--sorted_result
+SELECT * FROM t_1000 WHERE a < 1000 AND a > 98;
+#ALTER TABLE tp1 EXCHANGE PARTITION p2 WITH TABLE t_1000 IGNORE;
+#--sorted_result
+#SELECT * FROM tp1 WHERE a < 1000 AND a > 98;
+#--sorted_result
+#SELECT * FROM t_1000 WHERE a < 1000 AND a > 98;
+INSERT INTO tsp_03 VALUES (20, "Twenty");
+--error ER_ROW_DOES_NOT_MATCH_PARTITION
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+--sorted_result
+SELECT * FROM tsp;
+--sorted_result
+SELECT * FROM tsp_03;
+#ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03 IGNORE;
+#--sorted_result
+#SELECT * FROM tsp;
+#--sorted_result
+#SELECT * FROM tsp_03;
+
+DROP TABLE tp1;
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/inc/part_exch_qa_4.inc b/mysql-test/suite/parts/inc/part_exch_qa_4.inc
new file mode 100644
index 00000000000..d1de0298516
--- /dev/null
+++ b/mysql-test/suite/parts/inc/part_exch_qa_4.inc
@@ -0,0 +1,45 @@
+CREATE DATABASE test_2;
+
+USE test;
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+
+USE test_2;
+--source suite/parts/inc/part_exch_tabs.inc
+
+--enable_result_log
+--enable_query_log
+
+USE test;
+# 10) Exchanges with different databases.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE test_2.t_10;
+--sorted_result
+SELECT * FROM test_2.t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+# Back to former values.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE test_2.t_10;
+--sorted_result
+SELECT * FROM test_2.t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE test_2.tsp_00;
+--sorted_result
+SELECT * FROM test_2.tsp_00;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+# Back to former values.
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE test_2.tsp_00;
+--sorted_result
+SELECT * FROM test_2.tsp_00;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+USE test_2;
+--source suite/parts/inc/part_exch_drop_tabs.inc
+USE test;
+
+DROP DATABASE test_2;
+
diff --git a/mysql-test/suite/parts/inc/part_exch_qa_5.inc b/mysql-test/suite/parts/inc/part_exch_qa_5.inc
new file mode 100644
index 00000000000..1ad28df5f8c
--- /dev/null
+++ b/mysql-test/suite/parts/inc/part_exch_qa_5.inc
@@ -0,0 +1,89 @@
+--source include/not_embedded.inc
+
+CREATE USER test1@localhost;
+CREATE USER test2@localhost;
+GRANT USAGE ON *.* TO test1@localhost;
+GRANT USAGE ON *.* TO test2@localhost;
+GRANT CREATE, DROP, INSERT, SELECT ON test.* TO test1@localhost;
+GRANT CREATE, DROP, ALTER, UPDATE, INSERT, SELECT ON test.* TO test2@localhost;
+
+--echo connect (test1,localhost,test1,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test1,localhost,test1,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+SELECT current_user();
+SHOW GRANTS FOR CURRENT_USER;
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--echo disconnect test1;
+disconnect test1;
+
+
+--echo connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+USE test;
+SELECT current_user();
+SHOW GRANTS FOR CURRENT_USER;
+
+# 9) Exchanges with different owner.
+# Privilege for ALTER and SELECT
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+# Back to former values.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+# Back to former values.
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+--echo disconnect test2;
+disconnect test2;
+
+--echo connection default;
+connection default;
+REVOKE ALTER ON test.* FROM test2@localhost;
+
+--echo connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+USE test;
+SELECT current_user();
+SHOW GRANTS FOR CURRENT_USER;
+# Privilege for ALTER and SELECT
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+# Back to former values.
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+# Back to former values.
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+
+--echo connection default;
+connection default;
+--echo disconnect test2;
+disconnect test2;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
+DROP USER test1@localhost;
+DROP USER test2@localhost;
+
diff --git a/mysql-test/suite/parts/inc/part_exch_qa_7.inc b/mysql-test/suite/parts/inc/part_exch_qa_7.inc
new file mode 100644
index 00000000000..d8809902d51
--- /dev/null
+++ b/mysql-test/suite/parts/inc/part_exch_qa_7.inc
@@ -0,0 +1,63 @@
+CREATE USER test_2@localhost;
+
+--source include/not_embedded.inc
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+# 8) Exchanges partition and table and back in 2 sessions with an insert.
+# Parallel INSERT and SELECT
+# LOCK behaviour when exchanging different partitons.
+--echo send
+--send
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+
+--echo connect (test_2,localhost,test_2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test_2,localhost,test_2,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+# Wait until exchange has been done.
+let $wait_condition= SELECT count(a)>0 FROM tp WHERE a=1;
+--source include/wait_condition.inc
+# Expect 1,3,5,9 in tp and 2,4,6,8 in t_10
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+# Exchange back.
+INSERT INTO tp VALUES (7,"Seven");
+# Expect 2,4,6,8 in tp
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+
+--echo connection default;
+connection default;
+--echo reap;
+reap;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+
+--echo connection test_2;
+connection test_2;
+let $wait_condition= SELECT count(a)>0 FROM tp WHERE a=2;
+--source include/wait_condition.inc
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+--echo disconnect test_2;
+disconnect test_2;
+
+--echo connection default;
+connection default;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
+DROP USER test_2@localhost;
+
diff --git a/mysql-test/suite/parts/inc/part_exch_qa_8.inc b/mysql-test/suite/parts/inc/part_exch_qa_8.inc
new file mode 100644
index 00000000000..af0b5a9c6cd
--- /dev/null
+++ b/mysql-test/suite/parts/inc/part_exch_qa_8.inc
@@ -0,0 +1,71 @@
+CREATE USER test2@localhost;
+
+--source include/not_embedded.inc
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+CREATE DATABASE testdb;
+USE testdb;
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+USE test;
+GRANT CREATE, ALTER, DROP, INSERT, SELECT on test.* TO test2@localhost;
+GRANT CREATE, ALTER, DROP, INSERT, SELECT on testdb.* TO test2@localhost;
+
+# 8) Exchanges partition and table and back in 2 sessions with 2 databases.
+--echo connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+# Privileges on both DB's
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
+--sorted_result
+SELECT * FROM testdb.t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+# Exchange back.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
+--sorted_result
+SELECT * FROM testdb.t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+
+ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10;
+# Exchange back.
+ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10;
+--echo disconnect test2;
+disconnect test2;
+
+--echo connection default;
+connection default;
+REVOKE INSERT ON testdb.* FROM test2@localhost;
+
+--echo connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--echo disconnect test2;
+disconnect test2;
+
+--echo connection default;
+connection default;
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
+DROP USER test2@localhost;
+DROP DATABASE testdb;
+
diff --git a/mysql-test/suite/parts/inc/part_exch_tabs.inc b/mysql-test/suite/parts/inc/part_exch_tabs.inc
new file mode 100644
index 00000000000..378e0c2278d
--- /dev/null
+++ b/mysql-test/suite/parts/inc/part_exch_tabs.inc
@@ -0,0 +1,139 @@
+--disable_warnings
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+--enable_warnings
+
+eval CREATE TABLE t_10 (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a)) $data_directory $index_directory
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_100 (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a)) $data_directory $index_directory
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_1000 (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a)) $data_directory $index_directory
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_empty (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a)) $data_directory $index_directory
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_null (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a)) $data_directory $index_directory
+ENGINE = $engine_table;
+
+eval CREATE TABLE tp (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a)) $data_directory $index_directory
+ENGINE = $engine_part
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) $p_data_directory $p_index_directory,
+ PARTITION p1 VALUES LESS THAN (100) $p_data_directory $p_index_directory,
+ PARTITION p2 VALUES LESS THAN (1000) $p_data_directory $p_index_directory);
+
+eval CREATE TABLE tsp (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a)) $data_directory $index_directory
+ENGINE = $engine_subpart
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (10) $p_data_directory $p_index_directory
+ (SUBPARTITION sp00,
+ SUBPARTITION sp01,
+ SUBPARTITION sp02,
+ SUBPARTITION sp03,
+ SUBPARTITION sp04),
+ PARTITION p1 VALUES LESS THAN (100)
+ (SUBPARTITION sp10 $p_data_directory $p_index_directory,
+ SUBPARTITION sp11 $p_data_directory $p_index_directory,
+ SUBPARTITION sp12 $p_data_directory $p_index_directory,
+ SUBPARTITION sp13 $p_data_directory $p_index_directory,
+ SUBPARTITION sp14 $p_data_directory $p_index_directory),
+ PARTITION p2 VALUES LESS THAN (1000) $p_data_directory $p_index_directory
+ (SUBPARTITION sp20,
+ SUBPARTITION sp21,
+ SUBPARTITION sp22,
+ SUBPARTITION sp23,
+ SUBPARTITION sp24));
+
+# Values t_10 (not partitioned)
+INSERT INTO t_10 VALUES (1, "One"), (3, "Three"), (5, "Five"), (9, "Nine");
+
+# Values t_100 (not partitioned)
+INSERT INTO t_100 VALUES (11, "Eleven"), (13, "Thirdteen"), (15, "Fifeteen"), (19, "Nineteen");
+INSERT INTO t_100 VALUES (91, "Ninety-one"), (93, "Ninety-three"), (95, "Ninety-five"), (99, "Ninety-nine");
+
+# Values t_1000 (not partitioned)
+INSERT INTO t_1000 VALUES (111, "Hundred elven"), (113, "Hundred thirdteen"), (115, "Hundred fiveteen"), (119, "Hundred nineteen");
+INSERT INTO t_1000 VALUES (131, "Hundred thirty-one"), (133, "Hundred thirty-three"), (135, "Hundred thirty-five"), (139, "Hundred thirty-nine");
+INSERT INTO t_1000 VALUES (151, "Hundred fifty-one"), (153, "Hundred fifty-three"), (155, "Hundred fity-five"), (159, "Hundred fifty-nine");
+INSERT INTO t_1000 VALUES (191, "Hundred ninety-one"), (193, "Hundred ninety-three"), (195, "Hundred ninety-five"), (199, "Hundred ninety-nine");
+
+# Values t_null (not partitioned)
+INSERT INTO t_null VALUES (1, "NULL");
+
+# Values tp (partitions)
+INSERT INTO tp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight");
+INSERT INTO tp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen");
+INSERT INTO tp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen");
+INSERT INTO tp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight");
+INSERT INTO tp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight");
+INSERT INTO tp VALUES (182, "Hundred eighty-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight");
+
+# Values tps (subpartitions)
+INSERT INTO tsp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight");
+INSERT INTO tsp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen");
+INSERT INTO tsp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen");
+INSERT INTO tsp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight");
+INSERT INTO tsp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight");
+INSERT INTO tsp VALUES (182, "Hundred eight-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight");
+
+eval CREATE TABLE tsp_01(a INT,b VARCHAR(55),PRIMARY KEY (a))
+ ENGINE = $engine_table $data_directory $index_directory
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 1;
+eval CREATE TABLE tsp_02(a INT,b VARCHAR(55),PRIMARY KEY (a))
+ ENGINE = $engine_table $data_directory $index_directory
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 2;
+eval CREATE TABLE tsp_03(a INT,b VARCHAR(55),PRIMARY KEY (a))
+ ENGINE = $engine_table $data_directory $index_directory
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 3;
+eval CREATE TABLE tsp_04(a INT,b VARCHAR(55),PRIMARY KEY (a))
+ ENGINE = $engine_table $data_directory $index_directory
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 4;
+eval CREATE TABLE tsp_00(a INT,b VARCHAR(55),PRIMARY KEY (a))
+ ENGINE = $engine_table $data_directory $index_directory
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 0;
+
+SHOW CREATE TABLE t_10;
+SHOW CREATE TABLE t_100;
+SHOW CREATE TABLE t_1000;
+SHOW CREATE TABLE tp;
+SHOW CREATE TABLE tsp;
+
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM t_100;
+--sorted_result
+SELECT * FROM t_1000;
+--sorted_result
+SELECT * FROM tp;
+--sorted_result
+SELECT * FROM tp WHERE a< 10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 11 AND 100;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 101 AND 200;
+--sorted_result
+SELECT * FROM tsp;
diff --git a/mysql-test/suite/parts/inc/partition_exchange.inc b/mysql-test/suite/parts/inc/partition_exchange.inc
new file mode 100644
index 00000000000..f5ecddd13a4
--- /dev/null
+++ b/mysql-test/suite/parts/inc/partition_exchange.inc
@@ -0,0 +1,361 @@
+# Include file to test PARTITION EXCHANGE usable with different engines
+# Written by Mattias.Jonsson@Sun.Com
+
+--echo # Test with AUTO_INCREMENT
+eval CREATE TABLE tp
+(a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ b varchar(24))
+ENGINE = $engine
+PARTITION BY HASH (a) PARTITIONS 4;
+CREATE TABLE t LIKE tp;
+ALTER TABLE t REMOVE PARTITIONING;
+SHOW CREATE TABLE tp;
+SHOW CREATE TABLE t;
+INSERT INTO tp (b) VALUES ("One"), ("Two"), ("Three"), ("Four"), ("Five"),
+("Six"), ("Seven"), ("Eight"), ("Nine"), ("Ten"), ("Eleven"), ("Twelwe");
+if ($no_update)
+{
+# Archive handles auto inc by only allowing increasing values,
+# so this must be inserted before a higher value is inserted.
+INSERT INTO tp VALUES (41, "One hundred one");
+}
+INSERT INTO tp VALUES (97, "Ninety seven");
+if (!$no_delete)
+{
+INSERT INTO tp VALUES (111, "One hundred eleven");
+}
+if (!$no_update)
+{
+INSERT INTO tp VALUES (101, "One hundred one");
+}
+SET INSERT_ID = 13;
+INSERT INTO t (b) VALUES ("Thirteen");
+if ($no_update)
+{
+SET INSERT_ID = 17;
+INSERT INTO t (b) VALUES ("Twenty five");
+}
+SET INSERT_ID = 21;
+INSERT INTO t (b) VALUES ("Twenty one");
+if (!$no_update)
+{
+SET INSERT_ID = 25;
+INSERT INTO t (b) VALUES ("Twenty five");
+}
+if (!$no_delete)
+{
+SET INSERT_ID = 55;
+INSERT INTO t (b) VALUES ("Fifty five");
+DELETE FROM tp WHERE a = 111;
+DELETE FROM t WHERE a = 55;
+}
+if (!$no_update)
+{
+UPDATE tp SET a = 41 WHERE a = 101;
+UPDATE t SET a = 17 WHERE a = 25;
+}
+-- disable_query_log
+-- disable_result_log
+ANALYZE TABLE tp;
+-- enable_result_log
+-- enable_query_log
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t;
+-- disable_query_log
+-- disable_result_log
+ANALYZE TABLE tp;
+-- enable_result_log
+-- enable_query_log
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+SELECT * FROM tp ORDER BY a;
+SELECT * FROM t ORDER BY a;
+SHOW CREATE TABLE tp;
+SHOW CREATE TABLE t;
+DROP TABLE tp, t;
+
+# set a DEBUG_SYNC after open table and before verifying is done
+# Test that one can read from the table but not write, test that one can both
+# read and write to the partition
+# Verify that one must close the other instances of the table before the rename
+# takes place (i.e. no need for LOCK_open)
+# Test that it is not possible to drop, create, truncate either the tables or
+# partition
+# Test that it waits for ongoing transactions
+
+if ($no_keys)
+{
+eval CREATE TABLE t
+(a INT,
+ b VARCHAR(55))
+ENGINE = $engine;
+eval CREATE TABLE tp
+(a INT,
+ b VARCHAR(55))
+ENGINE = $engine
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100),
+ PARTITION p1 VALUES LESS THAN MAXVALUE);
+eval CREATE TABLE tsp
+(a INT,
+ b VARCHAR(55))
+ENGINE = $engine
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (100)
+ (SUBPARTITION sp0,
+ SUBPARTITION sp1),
+ PARTITION p1 VALUES LESS THAN MAXVALUE
+ (SUBPARTITION sp2,
+ SUBPARTITION sp3));
+}
+if (!$no_keys)
+{
+eval CREATE TABLE t
+(a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = $engine;
+eval CREATE TABLE tp
+(a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = $engine
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100),
+ PARTITION p1 VALUES LESS THAN MAXVALUE);
+eval CREATE TABLE tsp
+(a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = $engine
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (100)
+ (SUBPARTITION sp0,
+ SUBPARTITION sp1),
+ PARTITION p1 VALUES LESS THAN MAXVALUE
+ (SUBPARTITION sp2,
+ SUBPARTITION sp3));
+}
+
+INSERT INTO t VALUES (1, "First value"), (3, "Three"), (5, "Five"), (99, "End of values");
+INSERT INTO tp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+INSERT INTO tsp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+
+--echo # Start by testing read/write locking
+SET AUTOCOMMIT = 1;
+
+connect(con1, localhost, root,,);
+--echo # con1
+SET DEBUG_SYNC= 'swap_partition_after_compare_tables SIGNAL swap_in_progress WAIT_FOR goto_verification';
+SET DEBUG_SYNC= 'swap_partition_first_row_read SIGNAL swap_in_progress WAIT_FOR goto_wait';
+SET DEBUG_SYNC= 'swap_partition_after_wait SIGNAL swap_in_progress WAIT_FOR goto_rename';
+SET DEBUG_SYNC= 'swap_partition_before_rename SIGNAL swap_in_progress WAIT_FOR test_done';
+send ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+
+connection default;
+--echo # con default
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+--echo # select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+SELECT * FROM tp WHERE a = 61;
+--echo # any write (update/delete/insert) into t or tp should fail
+SET SESSION lock_wait_timeout=1;
+if (!$no_update)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+if (!$no_delete)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM tp WHERE a = 59;
+}
+if (!$no_update)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+if (!$no_delete)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM t WHERE a = 3;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+eval ALTER TABLE t ENGINE = $engine;
+--error ER_LOCK_WAIT_TIMEOUT
+eval ALTER TABLE tp ENGINE = $engine;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+SET DEBUG_SYNC= 'now SIGNAL goto_verification';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+--echo # select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+SELECT * FROM tp WHERE a = 61;
+if (!$no_update)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE tp SET a = 43, b = concat("Fifty three, was ", b) WHERE a = 63;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+if (!$no_delete)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM tp WHERE a = 59;
+}
+--echo # any write (update/delete/insert) into t should fail
+if (!$no_update)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+if (!$no_delete)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM t WHERE a = 3;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+eval ALTER TABLE t ENGINE = $engine;
+--error ER_LOCK_WAIT_TIMEOUT
+eval ALTER TABLE tp ENGINE = $engine;
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+SET DEBUG_SYNC= 'now SIGNAL goto_wait';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+--echo # Both tables should now be under exclusive lock, even SHOW should fail
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t WHERE a = 99;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM tp WHERE a = 61;
+if (!$no_update)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+if (!$no_delete)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM tp WHERE a = 59;
+}
+if (!$no_update)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+if (!$no_delete)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM t WHERE a = 3;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+SHOW CREATE TABLE t;
+--error ER_LOCK_WAIT_TIMEOUT
+SHOW CREATE TABLE tp;
+--error ER_LOCK_WAIT_TIMEOUT
+eval ALTER TABLE t ENGINE = $engine;
+--error ER_LOCK_WAIT_TIMEOUT
+eval ALTER TABLE tp ENGINE = $engine;
+SET DEBUG_SYNC= 'now SIGNAL goto_rename';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+--echo # Both tables should now be under exclusive lock
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM t WHERE a = 99;
+--error ER_LOCK_WAIT_TIMEOUT
+SELECT * FROM tp WHERE a = 61;
+if (!$no_update)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+if (!$no_delete)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM tp WHERE a = 59;
+}
+if (!$no_update)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+if (!$no_delete)
+{
+--error ER_LOCK_WAIT_TIMEOUT
+DELETE FROM t WHERE a = 3;
+}
+--error ER_LOCK_WAIT_TIMEOUT
+eval ALTER TABLE t ENGINE = $engine;
+--error ER_LOCK_WAIT_TIMEOUT
+eval ALTER TABLE tp ENGINE = $engine;
+--error ER_LOCK_WAIT_TIMEOUT
+SHOW CREATE TABLE t;
+--error ER_LOCK_WAIT_TIMEOUT
+SHOW CREATE TABLE tp;
+
+SET DEBUG_SYNC= 'now SIGNAL test_done';
+
+connection con1;
+--echo # con1
+--reap
+connection default;
+--echo # con default
+--echo # Tables should now be as normal
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+SELECT * FROM tp WHERE a = 99;
+SELECT * FROM t WHERE a = 61;
+if (!$no_update)
+{
+UPDATE t SET a = 53, b = "Fifty three, was sixty three" WHERE a = 63;
+}
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+if (!$no_delete)
+{
+DELETE FROM t WHERE a = 59;
+}
+if (!$no_update)
+{
+UPDATE tp SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+}
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+if (!$no_delete)
+{
+DELETE FROM tp WHERE a = 3;
+}
+eval ALTER TABLE t ENGINE = $engine;
+eval ALTER TABLE tp ENGINE = $engine;
+
+disconnect con1;
+connection default;
+--echo # con default
+SET DEBUG_SYNC= 'RESET';
+SHOW CREATE TABLE t;
+SHOW CREATE TABLE tp;
+--sorted_result
+SELECT * FROM t;
+--sorted_result
+SELECT * FROM tp;
+
+DROP TABLE t, tp, tsp;
+
+
diff --git a/mysql-test/suite/parts/inc/partition_mgm.inc b/mysql-test/suite/parts/inc/partition_mgm.inc
index 67d1feb8046..75834228d7a 100644
--- a/mysql-test/suite/parts/inc/partition_mgm.inc
+++ b/mysql-test/suite/parts/inc/partition_mgm.inc
@@ -57,6 +57,36 @@ ALTER TABLE TableA COALESCE PARTITION 4;
SELECT * FROM TableA;
SHOW CREATE TABLE TableA;
+-- disable_query_log
+-- disable_result_log
+ANALYZE TABLE TableA;
+-- enable_result_log
+-- enable_query_log
+
+--echo # Test of EXCHANGE PARTITION WITH TABLE
+if (!$native_partitioning)
+{
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+--sorted_result
+SELECT * FROM TableA;
+SHOW CREATE TABLE TableA;
+--sorted_result
+SELECT * FROM TableB;
+SHOW CREATE TABLE TableB;
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+--error ER_ROW_DOES_NOT_MATCH_PARTITION
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+DROP TABLE TableB;
+--sorted_result
+SELECT * FROM TableA;
+SHOW CREATE TABLE TableA;
+}
+
--echo # Test of REORGANIZE PARTITIONS
--echo # Should not work on HASH/KEY
--error ER_REORG_HASH_ONLY_ON_SAME_NO
diff --git a/mysql-test/suite/parts/r/partition_debug.result b/mysql-test/suite/parts/r/partition_debug.result
new file mode 100644
index 00000000000..3f0f2def790
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_debug.result
@@ -0,0 +1,1932 @@
+DROP TABLE IF EXISTS t1;
+#
+# WL#4445: EXCHANGE PARTITION WITH TABLE
+# Verify ddl_log in case of crashing.
+call mtr.add_suppression("Attempting backtrace. You can use the following information to find out");
+call mtr.add_suppression('InnoDB: The log sequence numbers [0-9]+ and [0-9]+ in ibdata files do not match the log sequence number [0-9]+ in the ib_logfiles!');
+SET SESSION debug_dbug="+d,exchange_partition_abort_1";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_abort_1";
+SET SESSION debug_dbug="+d,exchange_partition_abort_2";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_abort_2";
+SET SESSION debug_dbug="+d,exchange_partition_abort_3";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_abort_3";
+SET SESSION debug_dbug="+d,exchange_partition_abort_4";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sqlx-nnnn_nnnn.MYD
+#sqlx-nnnn_nnnn.MYI
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.frm
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_abort_4";
+SET SESSION debug_dbug="+d,exchange_partition_abort_5";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sqlx-nnnn_nnnn.MYD
+#sqlx-nnnn_nnnn.MYI
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.frm
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_abort_5";
+SET SESSION debug_dbug="+d,exchange_partition_abort_6";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sqlx-nnnn_nnnn.MYD
+#sqlx-nnnn_nnnn.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_abort_6";
+SET SESSION debug_dbug="+d,exchange_partition_abort_7";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+#sqlx-nnnn_nnnn.MYD
+#sqlx-nnnn_nnnn.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_abort_7";
+SET SESSION debug_dbug="+d,exchange_partition_abort_8";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_abort_8";
+SET SESSION debug_dbug="+d,exchange_partition_abort_9";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before crash
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Lost connection to MySQL server during query
+# State after crash (before recovery)
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+# State after crash recovery
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
+SELECT * FROM t1;
+a b
+11 Original from partition p1
+12 Original from partition p1
+13 Original from partition p1
+14 Original from partition p1
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+1 Original from partition p0
+2 Original from partition p0
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_abort_9";
+SET SESSION debug_dbug="+d,exchange_partition_fail_1";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Error in DDL log
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_fail_1";
+SET SESSION debug_dbug="+d,exchange_partition_fail_2";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Error in DDL log
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_fail_2";
+SET SESSION debug_dbug="+d,exchange_partition_fail_3";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Error on rename of './test/t2' to './test/#sqlx-nnnn_nnnn' (errno: 0 "Internal error/check (Not system error)")
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_fail_3";
+SET SESSION debug_dbug="+d,exchange_partition_fail_4";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Error in DDL log
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_fail_4";
+SET SESSION debug_dbug="+d,exchange_partition_fail_5";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Error on rename of './test/t1#P#p0' to './test/t2' (errno: 0 "Internal error/check (Not system error)")
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_fail_5";
+SET SESSION debug_dbug="+d,exchange_partition_fail_6";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Error in DDL log
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_fail_6";
+SET SESSION debug_dbug="+d,exchange_partition_fail_7";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Error on rename of './test/#sqlx-nnnn_nnnn' to './test/t1#P#p0' (errno: 0 "Internal error/check (Not system error)")
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_fail_7";
+SET SESSION debug_dbug="+d,exchange_partition_fail_8";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Error in DDL log
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_fail_8";
+SET SESSION debug_dbug="+d,exchange_partition_fail_9";
+CREATE TABLE t2 (a INT, b VARCHAR(64));
+INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+# State before failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE 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
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+3 Original from partition p0
+4 Original from partition p0
+ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+ERROR HY000: Error in DDL log
+# State after failure
+t1#P#p0.MYD
+t1#P#p0.MYI
+t1#P#p1.MYD
+t1#P#p1.MYI
+t1.frm
+t1.par
+t2.MYD
+t2.MYI
+t2.frm
+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 RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
+SELECT * FROM t1;
+a b
+11 Original from partition p1
+12 Original from partition p1
+13 Original from partition p1
+14 Original from partition p1
+21 Original from partition p1
+22 Original from partition p1
+23 Original from partition p1
+24 Original from partition p1
+5 Original from table t2
+6 Original from table t2
+7 Original from table t2
+8 Original from table t2
+DROP TABLE t1;
+SHOW CREATE TABLE t2;
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(64) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT * FROM t2;
+a b
+1 Original from partition p0
+2 Original from partition p0
+3 Original from partition p0
+4 Original from partition p0
+DROP TABLE t2;
+SET SESSION debug_dbug="-d,exchange_partition_fail_9";
diff --git a/mysql-test/suite/parts/r/partition_exch_innodb.result b/mysql-test/suite/parts/r/partition_exch_innodb.result
new file mode 100755
index 00000000000..d444e2e3558
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_innodb.result
@@ -0,0 +1,355 @@
+use test;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eight-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty;
+SELECT * FROM t_empty;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty;
+SELECT * FROM t_empty;
+a b
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 NULL
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+1 NULL
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+SELECT * FROM t_100;
+a b
+12 twelve
+14 Fourteen
+16 Sixteen
+18 Eightteen
+SELECT * FROM tp WHERE a BETWEEN 10 AND 100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM tp WHERE a BETWEEN 10 AND 100;
+a b
+12 twelve
+14 Fourteen
+16 Sixteen
+18 Eightteen
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000;
+SELECT * FROM t_1000;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+SELECT * FROM tp WHERE a BETWEEN 100 AND 1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000;
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp WHERE a BETWEEN 100 AND 1000;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01;
+ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02;
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04;
+SELECT * FROM tsp_00;
+a b
+SELECT * FROM tsp_01;
+a b
+6 Six
+SELECT * FROM tsp_02;
+a b
+2 Two
+SELECT * FROM tsp_03;
+a b
+8 Eight
+SELECT * FROM tsp_04;
+a b
+4 Four
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01;
+ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02;
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04;
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+6 Six
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+1 NULL
+2 Two
+4 Four
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+1 NULL
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_myisam.result b/mysql-test/suite/parts/r/partition_exch_myisam.result
new file mode 100755
index 00000000000..d444e2e3558
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_myisam.result
@@ -0,0 +1,355 @@
+use test;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eight-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty;
+SELECT * FROM t_empty;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty;
+SELECT * FROM t_empty;
+a b
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 NULL
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+1 NULL
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+SELECT * FROM t_100;
+a b
+12 twelve
+14 Fourteen
+16 Sixteen
+18 Eightteen
+SELECT * FROM tp WHERE a BETWEEN 10 AND 100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM tp WHERE a BETWEEN 10 AND 100;
+a b
+12 twelve
+14 Fourteen
+16 Sixteen
+18 Eightteen
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000;
+SELECT * FROM t_1000;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+SELECT * FROM tp WHERE a BETWEEN 100 AND 1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000;
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp WHERE a BETWEEN 100 AND 1000;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01;
+ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02;
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04;
+SELECT * FROM tsp_00;
+a b
+SELECT * FROM tsp_01;
+a b
+6 Six
+SELECT * FROM tsp_02;
+a b
+2 Two
+SELECT * FROM tsp_03;
+a b
+8 Eight
+SELECT * FROM tsp_04;
+a b
+4 Four
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01;
+ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02;
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04;
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+6 Six
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+1 NULL
+2 Two
+4 Four
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+1 NULL
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_myisam_innodb.result b/mysql-test/suite/parts/r/partition_exch_myisam_innodb.result
new file mode 100755
index 00000000000..9ff4afcfe35
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_myisam_innodb.result
@@ -0,0 +1,14 @@
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MariaDB
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa.result b/mysql-test/suite/parts/r/partition_exch_qa.result
new file mode 100755
index 00000000000..d444e2e3558
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa.result
@@ -0,0 +1,355 @@
+use test;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eight-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty;
+SELECT * FROM t_empty;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty;
+SELECT * FROM t_empty;
+a b
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 NULL
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+1 NULL
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+SELECT * FROM t_100;
+a b
+12 twelve
+14 Fourteen
+16 Sixteen
+18 Eightteen
+SELECT * FROM tp WHERE a BETWEEN 10 AND 100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM tp WHERE a BETWEEN 10 AND 100;
+a b
+12 twelve
+14 Fourteen
+16 Sixteen
+18 Eightteen
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000;
+SELECT * FROM t_1000;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+SELECT * FROM tp WHERE a BETWEEN 100 AND 1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000;
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp WHERE a BETWEEN 100 AND 1000;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01;
+ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02;
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04;
+SELECT * FROM tsp_00;
+a b
+SELECT * FROM tsp_01;
+a b
+6 Six
+SELECT * FROM tsp_02;
+a b
+2 Two
+SELECT * FROM tsp_03;
+a b
+8 Eight
+SELECT * FROM tsp_04;
+a b
+4 Four
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01;
+ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02;
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04;
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+6 Six
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+1 NULL
+2 Two
+4 Four
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null;
+SELECT * FROM t_null;
+a b
+1 NULL
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_10.result b/mysql-test/suite/parts/r/partition_exch_qa_10.result
new file mode 100755
index 00000000000..77b91f19e8f
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_10.result
@@ -0,0 +1,70 @@
+use test;
+CREATE PROCEDURE test_p1 ()
+BEGIN
+ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a);
+ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ALTER TABLE tp DROP INDEX a;
+ALTER TABLE t_10 DROP INDEX a;
+END|
+CALL test_p1;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 9;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+DROP PROCEDURE test_p1;
+SET @save_autocommit= @@autocommit;
+SET @@autocommit= OFF;
+SHOW VARIABLES LIKE '%autocommit%';
+Variable_name Value
+autocommit OFF
+CREATE TRIGGER test_trg_1 BEFORE UPDATE ON tp FOR EACH ROW
+BEGIN
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+END|
+ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
+CREATE FUNCTION test_f_1() RETURNS int
+BEGIN
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+END|
+ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
+SET @@autocommit= @save_autocommit;
+SET @save_event_scheduler= @@global.event_scheduler;
+SET @@global.event_scheduler= ON;
+CREATE EVENT test_ev_1
+ON SCHEDULE AT CURRENT_TIMESTAMP
+DO
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 9;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SET @@global.event_scheduler= @save_event_scheduler;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_11.result b/mysql-test/suite/parts/r/partition_exch_qa_11.result
new file mode 100755
index 00000000000..2fe6c05e29c
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_11.result
@@ -0,0 +1,56 @@
+use test;
+SET @part= 'p0';
+SET @part_tab= 'tp';
+SET @table= 't_10';
+SET @s= CONCAT('ALTER TABLE ',@part_tab,' EXCHANGE PARTITION ',@part,' WITH TABLE ',@table);
+PREPARE test_stmt1 FROM @s;
+EXECUTE test_stmt1;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp;
+a b
+1 One
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+3 Three
+5 Five
+9 Nine
+DEALLOCATE PREPARE test_stmt1;
+SET @part_tab= 'tp';
+SET @s= CONCAT('ALTER TABLE ',@part_tab,' EXCHANGE PARTITION ? WITH TABLE ?');
+PREPARE test_stmt2 FROM @s;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? WITH TABLE ?' at line 1
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_12.result b/mysql-test/suite/parts/r/partition_exch_qa_12.result
new file mode 100644
index 00000000000..32e0721e48f
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_12.result
@@ -0,0 +1,123 @@
+use test;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eight-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+SELECT TABLE_NAME, ROW_FORMAT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'test'
+AND TABLE_NAME IN ('tp', 't_100');
+TABLE_NAME ROW_FORMAT
+t_100 Dynamic
+tp Dynamic
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_1000;
+ERROR HY000: Non matching attribute 'MAX_ROWS' between partition and table
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_13.result b/mysql-test/suite/parts/r/partition_exch_qa_13.result
new file mode 100644
index 00000000000..476f33c0d47
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_13.result
@@ -0,0 +1,203 @@
+use test;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eight-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+INSERT INTO t_10 VALUES (10, "TEN");
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Found a row that does not match the partition
+SELECT * FROM tp WHERE a < 11;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM t_10 WHERE a < 11;
+a b
+1 One
+10 TEN
+3 Three
+5 Five
+9 Nine
+INSERT INTO t_1000 VALUES (99, "Ninetynine");
+ALTER TABLE tp1 EXCHANGE PARTITION p2 WITH TABLE t_1000;
+ERROR HY000: Found a row that does not match the partition
+SELECT * FROM tp1 WHERE a < 1000 AND a > 98;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+SELECT * FROM t_1000 WHERE a < 1000 AND a > 98;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+99 Ninetynine
+INSERT INTO tsp_03 VALUES (20, "Twenty");
+ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03;
+ERROR HY000: Found a row that does not match the partition
+SELECT * FROM tsp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eight-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp_03;
+a b
+20 Twenty
+3 Three
+DROP TABLE tp1;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_14.result b/mysql-test/suite/parts/r/partition_exch_qa_14.result
new file mode 100755
index 00000000000..f6866727184
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_14.result
@@ -0,0 +1,45 @@
+use test;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+use test;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+use test;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_15.result b/mysql-test/suite/parts/r/partition_exch_qa_15.result
new file mode 100644
index 00000000000..87671a74253
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_15.result
@@ -0,0 +1,19 @@
+use test;
+CREATE TABLE t_11 (a INT, b VARCHAR(55),
+FOREIGN KEY (a) REFERENCES t_10 (a) ON DELETE CASCADE)
+ENGINE= InnoDB;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+ERROR HY000: Table to exchange with partition has foreign key references: 't_11'
+DROP TABLE IF EXISTS t_11;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_1_innodb.result b/mysql-test/suite/parts/r/partition_exch_qa_1_innodb.result
new file mode 100644
index 00000000000..574518bff38
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_1_innodb.result
@@ -0,0 +1,171 @@
+use test;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eight-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+CREATE INDEX id_t_10_b USING BTREE ON t_10 (b);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+CREATE INDEX id_tp_b USING BTREE ON tp (b);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+DROP INDEX id_t_10_b ON t_10;
+DROP INDEX id_tp_b ON tp;
+ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+show create table t_10;
+Table Create Table
+t_10 CREATE TABLE `t_10` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `a` (`a`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+show create table tp ;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `a` (`a`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB,
+ PARTITION p1 VALUES LESS THAN (100) ENGINE = InnoDB,
+ PARTITION p2 VALUES LESS THAN (1000) ENGINE = InnoDB) */
+ALTER TABLE tp DROP INDEX a;
+ALTER TABLE t_10 DROP INDEX a;
+ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a,b);
+ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a,b);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+show create table t_10;
+Table Create Table
+t_10 CREATE TABLE `t_10` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `a` (`a`,`b`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+show create table tp ;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `a` (`a`,`b`) USING BTREE
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB,
+ PARTITION p1 VALUES LESS THAN (100) ENGINE = InnoDB,
+ PARTITION p2 VALUES LESS THAN (1000) ENGINE = InnoDB) */
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_1_myisam.result b/mysql-test/suite/parts/r/partition_exch_qa_1_myisam.result
new file mode 100644
index 00000000000..f15e56e76aa
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_1_myisam.result
@@ -0,0 +1,171 @@
+use test;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eight-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+CREATE INDEX id_t_10_b USING BTREE ON t_10 (b);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+CREATE INDEX id_tp_b USING BTREE ON tp (b);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+DROP INDEX id_t_10_b ON t_10;
+DROP INDEX id_tp_b ON tp;
+ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Tables have different definitions
+ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+show create table t_10;
+Table Create Table
+t_10 CREATE TABLE `t_10` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `a` (`a`) USING BTREE
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+show create table tp ;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `a` (`a`) USING BTREE
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN (100) ENGINE = MyISAM,
+ PARTITION p2 VALUES LESS THAN (1000) ENGINE = MyISAM) */
+ALTER TABLE tp DROP INDEX a;
+ALTER TABLE t_10 DROP INDEX a;
+ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a,b);
+ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a,b);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+show create table t_10;
+Table Create Table
+t_10 CREATE TABLE `t_10` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `a` (`a`,`b`) USING BTREE
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+show create table tp ;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`),
+ UNIQUE KEY `a` (`a`,`b`) USING BTREE
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN (100) ENGINE = MyISAM,
+ PARTITION p2 VALUES LESS THAN (1000) ENGINE = MyISAM) */
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_2.result b/mysql-test/suite/parts/r/partition_exch_qa_2.result
new file mode 100644
index 00000000000..ea4983db3dc
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_2.result
@@ -0,0 +1,138 @@
+use test;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM t_100;
+a b
+11 Eleven
+13 Thirdteen
+15 Fifeteen
+19 Nineteen
+91 Ninety-one
+93 Ninety-three
+95 Ninety-five
+99 Ninety-nine
+SELECT * FROM t_1000;
+a b
+111 Hundred elven
+113 Hundred thirdteen
+115 Hundred fiveteen
+119 Hundred nineteen
+131 Hundred thirty-one
+133 Hundred thirty-three
+135 Hundred thirty-five
+139 Hundred thirty-nine
+151 Hundred fifty-one
+153 Hundred fifty-three
+155 Hundred fity-five
+159 Hundred fifty-nine
+191 Hundred ninety-one
+193 Hundred ninety-three
+195 Hundred ninety-five
+199 Hundred ninety-nine
+SELECT * FROM tp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eighty-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp;
+a b
+112 Hundred twelve
+114 Hundred fourteen
+116 Hundred sixteen
+118 Hundred eightteen
+12 twelve
+122 Hundred twenty-two
+124 Hundred twenty-four
+126 Hundred twenty-six
+128 Hundred twenty-eight
+14 Fourteen
+16 Sixteen
+162 Hundred sixty-two
+164 Hundred sixty-four
+166 Hundred sixty-six
+168 Hundred sixty-eight
+18 Eightteen
+182 Hundred eight-two
+184 Hundred eighty-four
+186 Hundred eighty-six
+188 Hundred eighty-eight
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp_01;
+a b
+1 One
+SELECT * FROM tsp_02;
+a b
+SELECT * FROM tsp_03;
+a b
+3 Three
+SELECT * FROM tsp_04;
+a b
+9 Nine
+CREATE TABLE t_11(a INT,b VARCHAR(55)) SELECT * FROM t_10;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+ERROR HY000: Tables have different definitions
+DROP TABLE IF EXISTS t_11;
+CREATE TABLE t_11(a INT,b CHAR(55),PRIMARY KEY(a)) ENGINE= MYISAM SELECT * FROM t_10;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+ERROR HY000: Tables have different definitions
+DROP TABLE IF EXISTS t_11;
+CREATE TABLE t_11(a INT,b VARCHAR(55),PRIMARY KEY(a)) ENGINE= MEMORY SELECT * FROM t_10;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MariaDB
+DROP TABLE IF EXISTS t_11;
+CREATE TABLE t_11(a INT,b CHAR(55),PRIMARY KEY(a)) ENGINE= MYISAM
+PARTITION BY KEY() AS SELECT * FROM t_10;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+ERROR HY000: Table to exchange with partition is partitioned: 't_11'
+DROP TABLE IF EXISTS t_11;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE tsp;
+ERROR HY000: Table to exchange with partition is partitioned: 'tsp'
+ALTER TABLE tsp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: Subpartitioned table, use subpartition instead of partition
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_100;
+ERROR HY000: Found a row that does not match the partition
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_10;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_3.result b/mysql-test/suite/parts/r/partition_exch_qa_3.result
new file mode 100755
index 00000000000..9f4043a055a
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_3.result
@@ -0,0 +1,17 @@
+use test;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MariaDB
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MariaDB
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_4_innodb.result b/mysql-test/suite/parts/r/partition_exch_qa_4_innodb.result
new file mode 100755
index 00000000000..35f3499fce7
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_4_innodb.result
@@ -0,0 +1,76 @@
+CREATE DATABASE test_2;
+USE test;
+USE test;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE test_2.t_10;
+SELECT * FROM test_2.t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE test_2.t_10;
+SELECT * FROM test_2.t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE test_2.tsp_00;
+SELECT * FROM test_2.tsp_00;
+a b
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+5 Five
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE test_2.tsp_00;
+SELECT * FROM test_2.tsp_00;
+a b
+5 Five
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+USE test_2;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+USE test;
+DROP DATABASE test_2;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_4_myisam.result b/mysql-test/suite/parts/r/partition_exch_qa_4_myisam.result
new file mode 100755
index 00000000000..35f3499fce7
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_4_myisam.result
@@ -0,0 +1,76 @@
+CREATE DATABASE test_2;
+USE test;
+USE test;
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE test_2.t_10;
+SELECT * FROM test_2.t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE test_2.t_10;
+SELECT * FROM test_2.t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE test_2.tsp_00;
+SELECT * FROM test_2.tsp_00;
+a b
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+5 Five
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE test_2.tsp_00;
+SELECT * FROM test_2.tsp_00;
+a b
+5 Five
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+USE test_2;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+USE test;
+DROP DATABASE test_2;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_5_innodb.result b/mysql-test/suite/parts/r/partition_exch_qa_5_innodb.result
new file mode 100755
index 00000000000..e539c37a0b4
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_5_innodb.result
@@ -0,0 +1,114 @@
+CREATE USER test1@localhost;
+CREATE USER test2@localhost;
+GRANT USAGE ON *.* TO test1@localhost;
+GRANT USAGE ON *.* TO test2@localhost;
+GRANT CREATE, DROP, INSERT, SELECT ON test.* TO test1@localhost;
+GRANT CREATE, DROP, ALTER, UPDATE, INSERT, SELECT ON test.* TO test2@localhost;
+connect (test1,localhost,test1,,test,MASTER_MYPORT,MASTER_MYSOCK);
+SELECT current_user();
+current_user()
+test1@localhost
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test1@localhost
+GRANT USAGE ON *.* TO 'test1'@'localhost'
+GRANT SELECT, INSERT, CREATE, DROP ON `test`.* TO 'test1'@'localhost'
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: ALTER command denied to user 'test1'@'localhost' for table 'tp'
+disconnect test1;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+USE test;
+SELECT current_user();
+current_user()
+test2@localhost
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test2@localhost
+GRANT USAGE ON *.* TO 'test2'@'localhost'
+GRANT SELECT, INSERT, UPDATE, CREATE, DROP, ALTER ON `test`.* TO 'test2'@'localhost'
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+SELECT * FROM tsp_00;
+a b
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+5 Five
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+disconnect test2;
+connection default;
+REVOKE ALTER ON test.* FROM test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+USE test;
+SELECT current_user();
+current_user()
+test2@localhost
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test2@localhost
+GRANT USAGE ON *.* TO 'test2'@'localhost'
+GRANT SELECT, INSERT, UPDATE, CREATE, DROP ON `test`.* TO 'test2'@'localhost'
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: ALTER command denied to user 'test2'@'localhost' for table 'tp'
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: ALTER command denied to user 'test2'@'localhost' for table 'tp'
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ERROR 42000: ALTER command denied to user 'test2'@'localhost' for table 'tsp'
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ERROR 42000: ALTER command denied to user 'test2'@'localhost' for table 'tsp'
+connection default;
+disconnect test2;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+DROP USER test1@localhost;
+DROP USER test2@localhost;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_5_myisam.result b/mysql-test/suite/parts/r/partition_exch_qa_5_myisam.result
new file mode 100755
index 00000000000..e539c37a0b4
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_5_myisam.result
@@ -0,0 +1,114 @@
+CREATE USER test1@localhost;
+CREATE USER test2@localhost;
+GRANT USAGE ON *.* TO test1@localhost;
+GRANT USAGE ON *.* TO test2@localhost;
+GRANT CREATE, DROP, INSERT, SELECT ON test.* TO test1@localhost;
+GRANT CREATE, DROP, ALTER, UPDATE, INSERT, SELECT ON test.* TO test2@localhost;
+connect (test1,localhost,test1,,test,MASTER_MYPORT,MASTER_MYSOCK);
+SELECT current_user();
+current_user()
+test1@localhost
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test1@localhost
+GRANT USAGE ON *.* TO 'test1'@'localhost'
+GRANT SELECT, INSERT, CREATE, DROP ON `test`.* TO 'test1'@'localhost'
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: ALTER command denied to user 'test1'@'localhost' for table 'tp'
+disconnect test1;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+USE test;
+SELECT current_user();
+current_user()
+test2@localhost
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test2@localhost
+GRANT USAGE ON *.* TO 'test2'@'localhost'
+GRANT SELECT, INSERT, UPDATE, CREATE, DROP, ALTER ON `test`.* TO 'test2'@'localhost'
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+SELECT * FROM tsp_00;
+a b
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+5 Five
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+disconnect test2;
+connection default;
+REVOKE ALTER ON test.* FROM test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+USE test;
+SELECT current_user();
+current_user()
+test2@localhost
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test2@localhost
+GRANT USAGE ON *.* TO 'test2'@'localhost'
+GRANT SELECT, INSERT, UPDATE, CREATE, DROP ON `test`.* TO 'test2'@'localhost'
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: ALTER command denied to user 'test2'@'localhost' for table 'tp'
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: ALTER command denied to user 'test2'@'localhost' for table 'tp'
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ERROR 42000: ALTER command denied to user 'test2'@'localhost' for table 'tsp'
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ERROR 42000: ALTER command denied to user 'test2'@'localhost' for table 'tsp'
+connection default;
+disconnect test2;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+DROP USER test1@localhost;
+DROP USER test2@localhost;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_6.result b/mysql-test/suite/parts/r/partition_exch_qa_6.result
new file mode 100755
index 00000000000..92527ab1dd9
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_6.result
@@ -0,0 +1,105 @@
+CREATE USER test2@localhost;
+GRANT USAGE ON *.* TO test2@localhost;
+GRANT CREATE, DROP, ALTER, UPDATE, INSERT, SELECT ON test.* TO test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+USE test;
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test2@localhost
+GRANT USAGE ON *.* TO 'test2'@'localhost'
+GRANT SELECT, INSERT, UPDATE, CREATE, DROP, ALTER ON `test`.* TO 'test2'@'localhost'
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+SELECT * FROM tsp_00;
+a b
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+5 Five
+6 Six
+8 Eight
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+SELECT * FROM tsp_00;
+a b
+5 Five
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+disconnect test2;
+connection default;
+REVOKE INSERT ON test.* FROM test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+USE test;
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test2@localhost
+GRANT USAGE ON *.* TO 'test2'@'localhost'
+GRANT SELECT, UPDATE, CREATE, DROP, ALTER ON `test`.* TO 'test2'@'localhost'
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: INSERT command denied to user 'test2'@'localhost' for table 'tp'
+disconnect test2;
+connection default;
+GRANT INSERT ON test.* TO test2@localhost;
+REVOKE CREATE ON test.* FROM test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+USE test;
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test2@localhost
+GRANT USAGE ON *.* TO 'test2'@'localhost'
+GRANT SELECT, INSERT, UPDATE, DROP, ALTER ON `test`.* TO 'test2'@'localhost'
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+ERROR 42000: CREATE command denied to user 'test2'@'localhost' for table 'tsp'
+disconnect test2;
+connection default;
+GRANT CREATE ON test.* TO test2@localhost;
+REVOKE DROP ON test.* FROM test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+USE test;
+SHOW GRANTS FOR CURRENT_USER;
+Grants for test2@localhost
+GRANT USAGE ON *.* TO 'test2'@'localhost'
+GRANT SELECT, INSERT, UPDATE, CREATE, ALTER ON `test`.* TO 'test2'@'localhost'
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: DROP command denied to user 'test2'@'localhost' for table 'tp'
+disconnect test2;
+connection default;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+DROP USER test2@localhost;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_7_innodb.result b/mysql-test/suite/parts/r/partition_exch_qa_7_innodb.result
new file mode 100755
index 00000000000..8ae4bfd3d3a
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_7_innodb.result
@@ -0,0 +1,82 @@
+CREATE USER test_2@localhost;
+send
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+connect (test_2,localhost,test_2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+INSERT INTO tp VALUES (7,"Seven");
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+7 Seven
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+connection default;
+reap;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+7 Seven
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+connection test_2;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+7 Seven
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+disconnect test_2;
+connection default;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+7 Seven
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+DROP USER test_2@localhost;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_7_myisam.result b/mysql-test/suite/parts/r/partition_exch_qa_7_myisam.result
new file mode 100755
index 00000000000..8ae4bfd3d3a
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_7_myisam.result
@@ -0,0 +1,82 @@
+CREATE USER test_2@localhost;
+send
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+connect (test_2,localhost,test_2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+INSERT INTO tp VALUES (7,"Seven");
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+7 Seven
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+connection default;
+reap;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+7 Seven
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+connection test_2;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+7 Seven
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+disconnect test_2;
+connection default;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+7 Seven
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+DROP USER test_2@localhost;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_8_innodb.result b/mysql-test/suite/parts/r/partition_exch_qa_8_innodb.result
new file mode 100755
index 00000000000..b252fc616b1
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_8_innodb.result
@@ -0,0 +1,83 @@
+CREATE USER test2@localhost;
+CREATE DATABASE testdb;
+USE testdb;
+USE test;
+GRANT CREATE, ALTER, DROP, INSERT, SELECT on test.* TO test2@localhost;
+GRANT CREATE, ALTER, DROP, INSERT, SELECT on testdb.* TO test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
+SELECT * FROM testdb.t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
+SELECT * FROM testdb.t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+disconnect test2;
+connection default;
+REVOKE INSERT ON testdb.* FROM test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
+ERROR 42000: INSERT command denied to user 'test2'@'localhost' for table 't_10'
+ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: INSERT command denied to user 'test2'@'localhost' for table 'tp'
+disconnect test2;
+connection default;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+DROP USER test2@localhost;
+DROP DATABASE testdb;
diff --git a/mysql-test/suite/parts/r/partition_exch_qa_8_myisam.result b/mysql-test/suite/parts/r/partition_exch_qa_8_myisam.result
new file mode 100755
index 00000000000..b252fc616b1
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exch_qa_8_myisam.result
@@ -0,0 +1,83 @@
+CREATE USER test2@localhost;
+CREATE DATABASE testdb;
+USE testdb;
+USE test;
+GRANT CREATE, ALTER, DROP, INSERT, SELECT on test.* TO test2@localhost;
+GRANT CREATE, ALTER, DROP, INSERT, SELECT on testdb.* TO test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
+SELECT * FROM testdb.t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
+SELECT * FROM testdb.t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+SELECT * FROM t_10;
+a b
+1 One
+3 Three
+5 Five
+9 Nine
+SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10;
+a b
+2 Two
+4 Four
+6 Six
+8 Eight
+disconnect test2;
+connection default;
+REVOKE INSERT ON testdb.* FROM test2@localhost;
+connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10;
+ERROR 42000: INSERT command denied to user 'test2'@'localhost' for table 't_10'
+ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ERROR 42000: INSERT command denied to user 'test2'@'localhost' for table 'tp'
+disconnect test2;
+connection default;
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS tsp_00;
+DROP TABLE IF EXISTS tsp_01;
+DROP TABLE IF EXISTS tsp_02;
+DROP TABLE IF EXISTS tsp_03;
+DROP TABLE IF EXISTS tsp_04;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+DROP USER test2@localhost;
+DROP DATABASE testdb;
diff --git a/mysql-test/suite/parts/r/partition_exchange_archive.result b/mysql-test/suite/parts/r/partition_exchange_archive.result
new file mode 100644
index 00000000000..2918c2eed31
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exchange_archive.result
@@ -0,0 +1,322 @@
+# Archive does not support keys, update or delete
+# Test with AUTO_INCREMENT
+CREATE TABLE tp
+(a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+b varchar(24))
+ENGINE = 'Archive'
+PARTITION BY HASH (a) PARTITIONS 4;
+CREATE TABLE t LIKE tp;
+ALTER TABLE t REMOVE PARTITIONING;
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY HASH (a)
+PARTITIONS 4 */
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+INSERT INTO tp (b) VALUES ("One"), ("Two"), ("Three"), ("Four"), ("Five"),
+("Six"), ("Seven"), ("Eight"), ("Nine"), ("Ten"), ("Eleven"), ("Twelwe");
+INSERT INTO tp VALUES (41, "One hundred one");
+INSERT INTO tp VALUES (97, "Ninety seven");
+SET INSERT_ID = 13;
+INSERT INTO t (b) VALUES ("Thirteen");
+SET INSERT_ID = 17;
+INSERT INTO t (b) VALUES ("Twenty five");
+SET INSERT_ID = 21;
+INSERT INTO t (b) VALUES ("Twenty one");
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+PARTITION_NAME HAVE_ROWS
+p0 YES
+p1 YES
+p2 YES
+p3 YES
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+HAVE_ROWS
+YES
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t;
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+PARTITION_NAME HAVE_ROWS
+p0 YES
+p1 YES
+p2 YES
+p3 YES
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+HAVE_ROWS
+YES
+SELECT * FROM tp ORDER BY a;
+a b
+2 Two
+3 Three
+4 Four
+6 Six
+7 Seven
+8 Eight
+10 Ten
+11 Eleven
+12 Twelwe
+13 Thirteen
+17 Twenty five
+21 Twenty one
+SELECT * FROM t ORDER BY a;
+a b
+1 One
+5 Five
+9 Nine
+41 One hundred one
+97 Ninety seven
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=ARCHIVE AUTO_INCREMENT=22 DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY HASH (a)
+PARTITIONS 4 */
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=ARCHIVE AUTO_INCREMENT=98 DEFAULT CHARSET=latin1
+DROP TABLE tp, t;
+CREATE TABLE t
+(a INT,
+b VARCHAR(55))
+ENGINE = 'Archive';
+CREATE TABLE tp
+(a INT,
+b VARCHAR(55))
+ENGINE = 'Archive'
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+CREATE TABLE tsp
+(a INT,
+b VARCHAR(55))
+ENGINE = 'Archive'
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (100)
+(SUBPARTITION sp0,
+SUBPARTITION sp1),
+PARTITION p1 VALUES LESS THAN MAXVALUE
+(SUBPARTITION sp2,
+SUBPARTITION sp3));
+INSERT INTO t VALUES (1, "First value"), (3, "Three"), (5, "Five"), (99, "End of values");
+INSERT INTO tp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+INSERT INTO tsp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+SELECT * FROM t;
+a b
+1 First value
+3 Three
+5 Five
+99 End of values
+SELECT * FROM tp;
+a b
+10 Ten
+161 161
+162 162
+163 163
+164 164
+2 First value
+200 Two hundred, end of values
+50 Fifty
+61 Sixty one
+62 Sixty two
+63 Sixty three
+64 Sixty four
+# Start by testing read/write locking
+SET AUTOCOMMIT = 1;
+# con1
+SET DEBUG_SYNC= 'swap_partition_after_compare_tables SIGNAL swap_in_progress WAIT_FOR goto_verification';
+SET DEBUG_SYNC= 'swap_partition_first_row_read SIGNAL swap_in_progress WAIT_FOR goto_wait';
+SET DEBUG_SYNC= 'swap_partition_after_wait SIGNAL swap_in_progress WAIT_FOR goto_rename';
+SET DEBUG_SYNC= 'swap_partition_before_rename SIGNAL swap_in_progress WAIT_FOR test_done';
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+# con default
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM tp WHERE a = 61;
+a b
+61 Sixty one
+# any write (update/delete/insert) into t or tp should fail
+SET SESSION lock_wait_timeout=1;
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'Archive';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'Archive';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(55) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(55) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = ARCHIVE,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = ARCHIVE) */
+SET DEBUG_SYNC= 'now SIGNAL goto_verification';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM tp WHERE a = 61;
+a b
+61 Sixty one
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+# any write (update/delete/insert) into t should fail
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'Archive';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'Archive';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(55) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(55) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = ARCHIVE,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = ARCHIVE) */
+SET DEBUG_SYNC= 'now SIGNAL goto_wait';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# Both tables should now be under exclusive lock, even SHOW should fail
+SELECT * FROM t WHERE a = 99;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM tp WHERE a = 61;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE tp;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'Archive';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'Archive';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SET DEBUG_SYNC= 'now SIGNAL goto_rename';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# Both tables should now be under exclusive lock
+SELECT * FROM t WHERE a = 99;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM tp WHERE a = 61;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'Archive';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'Archive';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE tp;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SET DEBUG_SYNC= 'now SIGNAL test_done';
+# con1
+# con default
+# Tables should now be as normal
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(55) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(55) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = ARCHIVE,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = ARCHIVE) */
+SELECT * FROM tp WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM t WHERE a = 61;
+a b
+61 Sixty one
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ALTER TABLE t ENGINE = 'Archive';
+ALTER TABLE tp ENGINE = 'Archive';
+# con default
+SET DEBUG_SYNC= 'RESET';
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(55) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) DEFAULT NULL,
+ `b` varchar(55) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = ARCHIVE,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = ARCHIVE) */
+SELECT * FROM t;
+a b
+10 Ten
+2 First value
+50 Fifty
+59 To be deleted
+61 Sixty one
+62 Sixty two
+63 Sixty three
+63 Sixty three, new
+64 Sixty four
+SELECT * FROM tp;
+a b
+1 First value
+161 161
+162 162
+163 163
+164 164
+200 Two hundred, end of values
+3 Three
+5 Five
+59 To be deleted
+63 Sixty three, new
+99 End of values
+DROP TABLE t, tp, tsp;
diff --git a/mysql-test/suite/parts/r/partition_exchange_blackhole.result b/mysql-test/suite/parts/r/partition_exchange_blackhole.result
new file mode 100644
index 00000000000..f293bd8f960
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exchange_blackhole.result
@@ -0,0 +1,10 @@
+# Blackhole has not implemented check_if_incompatible_data,
+# so it cannot support EXCHANGE PARTITION
+CREATE TABLE t (a int, b varchar(55)) ENGINE = 'Blackhole';
+CREATE TABLE tp (a int, b varchar(55)) ENGINE = 'Blackhole'
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+ERROR HY000: Tables have different definitions
+DROP TABLE t, tp;
diff --git a/mysql-test/suite/parts/r/partition_exchange_innodb.result b/mysql-test/suite/parts/r/partition_exchange_innodb.result
new file mode 100644
index 00000000000..d3287310f73
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exchange_innodb.result
@@ -0,0 +1,374 @@
+# Test with AUTO_INCREMENT
+CREATE TABLE tp
+(a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+b varchar(24))
+ENGINE = 'InnoDB'
+PARTITION BY HASH (a) PARTITIONS 4;
+CREATE TABLE t LIKE tp;
+ALTER TABLE t REMOVE PARTITIONING;
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY HASH (a)
+PARTITIONS 4 */
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+INSERT INTO tp (b) VALUES ("One"), ("Two"), ("Three"), ("Four"), ("Five"),
+("Six"), ("Seven"), ("Eight"), ("Nine"), ("Ten"), ("Eleven"), ("Twelwe");
+INSERT INTO tp VALUES (97, "Ninety seven");
+INSERT INTO tp VALUES (111, "One hundred eleven");
+INSERT INTO tp VALUES (101, "One hundred one");
+SET INSERT_ID = 13;
+INSERT INTO t (b) VALUES ("Thirteen");
+SET INSERT_ID = 21;
+INSERT INTO t (b) VALUES ("Twenty one");
+SET INSERT_ID = 25;
+INSERT INTO t (b) VALUES ("Twenty five");
+SET INSERT_ID = 55;
+INSERT INTO t (b) VALUES ("Fifty five");
+DELETE FROM tp WHERE a = 111;
+DELETE FROM t WHERE a = 55;
+UPDATE tp SET a = 41 WHERE a = 101;
+UPDATE t SET a = 17 WHERE a = 25;
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+PARTITION_NAME HAVE_ROWS
+p0 YES
+p1 YES
+p2 YES
+p3 YES
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+HAVE_ROWS
+YES
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t;
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+PARTITION_NAME HAVE_ROWS
+p0 YES
+p1 YES
+p2 YES
+p3 YES
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+HAVE_ROWS
+YES
+SELECT * FROM tp ORDER BY a;
+a b
+2 Two
+3 Three
+4 Four
+6 Six
+7 Seven
+8 Eight
+10 Ten
+11 Eleven
+12 Twelwe
+13 Thirteen
+17 Twenty five
+21 Twenty one
+SELECT * FROM t ORDER BY a;
+a b
+1 One
+5 Five
+9 Nine
+41 One hundred one
+97 Ninety seven
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB AUTO_INCREMENT=112 DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY HASH (a)
+PARTITIONS 4 */
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB AUTO_INCREMENT=102 DEFAULT CHARSET=latin1
+DROP TABLE tp, t;
+CREATE TABLE t
+(a INT,
+b VARCHAR(55),
+PRIMARY KEY (a))
+ENGINE = 'InnoDB';
+CREATE TABLE tp
+(a INT,
+b VARCHAR(55),
+PRIMARY KEY (a))
+ENGINE = 'InnoDB'
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+CREATE TABLE tsp
+(a INT,
+b VARCHAR(55),
+PRIMARY KEY (a))
+ENGINE = 'InnoDB'
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (100)
+(SUBPARTITION sp0,
+SUBPARTITION sp1),
+PARTITION p1 VALUES LESS THAN MAXVALUE
+(SUBPARTITION sp2,
+SUBPARTITION sp3));
+INSERT INTO t VALUES (1, "First value"), (3, "Three"), (5, "Five"), (99, "End of values");
+INSERT INTO tp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+INSERT INTO tsp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+SELECT * FROM t;
+a b
+1 First value
+3 Three
+5 Five
+99 End of values
+SELECT * FROM tp;
+a b
+10 Ten
+161 161
+162 162
+163 163
+164 164
+2 First value
+200 Two hundred, end of values
+50 Fifty
+61 Sixty one
+62 Sixty two
+63 Sixty three
+64 Sixty four
+# Start by testing read/write locking
+SET AUTOCOMMIT = 1;
+# con1
+SET DEBUG_SYNC= 'swap_partition_after_compare_tables SIGNAL swap_in_progress WAIT_FOR goto_verification';
+SET DEBUG_SYNC= 'swap_partition_first_row_read SIGNAL swap_in_progress WAIT_FOR goto_wait';
+SET DEBUG_SYNC= 'swap_partition_after_wait SIGNAL swap_in_progress WAIT_FOR goto_rename';
+SET DEBUG_SYNC= 'swap_partition_before_rename SIGNAL swap_in_progress WAIT_FOR test_done';
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+# con default
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM tp WHERE a = 61;
+a b
+61 Sixty one
+# any write (update/delete/insert) into t or tp should fail
+SET SESSION lock_wait_timeout=1;
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'InnoDB';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'InnoDB';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = InnoDB,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
+SET DEBUG_SYNC= 'now SIGNAL goto_verification';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM tp WHERE a = 61;
+a b
+61 Sixty one
+UPDATE tp SET a = 43, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+# any write (update/delete/insert) into t should fail
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'InnoDB';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'InnoDB';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = InnoDB,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
+SET DEBUG_SYNC= 'now SIGNAL goto_wait';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# Both tables should now be under exclusive lock, even SHOW should fail
+SELECT * FROM t WHERE a = 99;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM tp WHERE a = 61;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE tp;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'InnoDB';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'InnoDB';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SET DEBUG_SYNC= 'now SIGNAL goto_rename';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# Both tables should now be under exclusive lock
+SELECT * FROM t WHERE a = 99;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM tp WHERE a = 61;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'InnoDB';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'InnoDB';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE tp;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SET DEBUG_SYNC= 'now SIGNAL test_done';
+# con1
+# con default
+# Tables should now be as normal
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = InnoDB,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
+SELECT * FROM tp WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM t WHERE a = 61;
+a b
+61 Sixty one
+UPDATE t SET a = 53, b = "Fifty three, was sixty three" WHERE a = 63;
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+DELETE FROM t WHERE a = 59;
+UPDATE tp SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+DELETE FROM tp WHERE a = 3;
+ALTER TABLE t ENGINE = 'InnoDB';
+ALTER TABLE tp ENGINE = 'InnoDB';
+# con default
+SET DEBUG_SYNC= 'RESET';
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = InnoDB,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */
+SELECT * FROM t;
+a b
+10 Ten
+2 First value
+50 Fifty
+53 Fifty three, was sixty three
+61 Sixty one
+62 Sixty two
+63 Sixty three, new
+64 Sixty four
+SELECT * FROM tp;
+a b
+1 First value
+161 161
+162 162
+163 163
+164 164
+200 Two hundred, end of values
+5 Five
+53 Fifty three, was three
+59 To be deleted
+63 Sixty three, new
+99 End of values
+DROP TABLE t, tp, tsp;
diff --git a/mysql-test/suite/parts/r/partition_exchange_memory.result b/mysql-test/suite/parts/r/partition_exchange_memory.result
new file mode 100644
index 00000000000..b6df8259b8c
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exchange_memory.result
@@ -0,0 +1,374 @@
+# Test with AUTO_INCREMENT
+CREATE TABLE tp
+(a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+b varchar(24))
+ENGINE = 'Memory'
+PARTITION BY HASH (a) PARTITIONS 4;
+CREATE TABLE t LIKE tp;
+ALTER TABLE t REMOVE PARTITIONING;
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY HASH (a)
+PARTITIONS 4 */
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+INSERT INTO tp (b) VALUES ("One"), ("Two"), ("Three"), ("Four"), ("Five"),
+("Six"), ("Seven"), ("Eight"), ("Nine"), ("Ten"), ("Eleven"), ("Twelwe");
+INSERT INTO tp VALUES (97, "Ninety seven");
+INSERT INTO tp VALUES (111, "One hundred eleven");
+INSERT INTO tp VALUES (101, "One hundred one");
+SET INSERT_ID = 13;
+INSERT INTO t (b) VALUES ("Thirteen");
+SET INSERT_ID = 21;
+INSERT INTO t (b) VALUES ("Twenty one");
+SET INSERT_ID = 25;
+INSERT INTO t (b) VALUES ("Twenty five");
+SET INSERT_ID = 55;
+INSERT INTO t (b) VALUES ("Fifty five");
+DELETE FROM tp WHERE a = 111;
+DELETE FROM t WHERE a = 55;
+UPDATE tp SET a = 41 WHERE a = 101;
+UPDATE t SET a = 17 WHERE a = 25;
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+PARTITION_NAME HAVE_ROWS
+p0 YES
+p1 YES
+p2 YES
+p3 YES
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+HAVE_ROWS
+YES
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t;
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+PARTITION_NAME HAVE_ROWS
+p0 YES
+p1 YES
+p2 YES
+p3 YES
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+HAVE_ROWS
+YES
+SELECT * FROM tp ORDER BY a;
+a b
+2 Two
+3 Three
+4 Four
+6 Six
+7 Seven
+8 Eight
+10 Ten
+11 Eleven
+12 Twelwe
+13 Thirteen
+17 Twenty five
+21 Twenty one
+SELECT * FROM t ORDER BY a;
+a b
+1 One
+5 Five
+9 Nine
+41 One hundred one
+97 Ninety seven
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY AUTO_INCREMENT=112 DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY HASH (a)
+PARTITIONS 4 */
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY AUTO_INCREMENT=102 DEFAULT CHARSET=latin1
+DROP TABLE tp, t;
+CREATE TABLE t
+(a INT,
+b VARCHAR(55),
+PRIMARY KEY (a))
+ENGINE = 'Memory';
+CREATE TABLE tp
+(a INT,
+b VARCHAR(55),
+PRIMARY KEY (a))
+ENGINE = 'Memory'
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+CREATE TABLE tsp
+(a INT,
+b VARCHAR(55),
+PRIMARY KEY (a))
+ENGINE = 'Memory'
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (100)
+(SUBPARTITION sp0,
+SUBPARTITION sp1),
+PARTITION p1 VALUES LESS THAN MAXVALUE
+(SUBPARTITION sp2,
+SUBPARTITION sp3));
+INSERT INTO t VALUES (1, "First value"), (3, "Three"), (5, "Five"), (99, "End of values");
+INSERT INTO tp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+INSERT INTO tsp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+SELECT * FROM t;
+a b
+1 First value
+3 Three
+5 Five
+99 End of values
+SELECT * FROM tp;
+a b
+10 Ten
+161 161
+162 162
+163 163
+164 164
+2 First value
+200 Two hundred, end of values
+50 Fifty
+61 Sixty one
+62 Sixty two
+63 Sixty three
+64 Sixty four
+# Start by testing read/write locking
+SET AUTOCOMMIT = 1;
+# con1
+SET DEBUG_SYNC= 'swap_partition_after_compare_tables SIGNAL swap_in_progress WAIT_FOR goto_verification';
+SET DEBUG_SYNC= 'swap_partition_first_row_read SIGNAL swap_in_progress WAIT_FOR goto_wait';
+SET DEBUG_SYNC= 'swap_partition_after_wait SIGNAL swap_in_progress WAIT_FOR goto_rename';
+SET DEBUG_SYNC= 'swap_partition_before_rename SIGNAL swap_in_progress WAIT_FOR test_done';
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+# con default
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM tp WHERE a = 61;
+a b
+61 Sixty one
+# any write (update/delete/insert) into t or tp should fail
+SET SESSION lock_wait_timeout=1;
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'Memory';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'Memory';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = MEMORY,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MEMORY) */
+SET DEBUG_SYNC= 'now SIGNAL goto_verification';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM tp WHERE a = 61;
+a b
+61 Sixty one
+UPDATE tp SET a = 43, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+# any write (update/delete/insert) into t should fail
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'Memory';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'Memory';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = MEMORY,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MEMORY) */
+SET DEBUG_SYNC= 'now SIGNAL goto_wait';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# Both tables should now be under exclusive lock, even SHOW should fail
+SELECT * FROM t WHERE a = 99;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM tp WHERE a = 61;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE tp;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'Memory';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'Memory';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SET DEBUG_SYNC= 'now SIGNAL goto_rename';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# Both tables should now be under exclusive lock
+SELECT * FROM t WHERE a = 99;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM tp WHERE a = 61;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'Memory';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'Memory';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE tp;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SET DEBUG_SYNC= 'now SIGNAL test_done';
+# con1
+# con default
+# Tables should now be as normal
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = MEMORY,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MEMORY) */
+SELECT * FROM tp WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM t WHERE a = 61;
+a b
+61 Sixty one
+UPDATE t SET a = 53, b = "Fifty three, was sixty three" WHERE a = 63;
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+DELETE FROM t WHERE a = 59;
+UPDATE tp SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+DELETE FROM tp WHERE a = 3;
+ALTER TABLE t ENGINE = 'Memory';
+ALTER TABLE tp ENGINE = 'Memory';
+# con default
+SET DEBUG_SYNC= 'RESET';
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = MEMORY,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MEMORY) */
+SELECT * FROM t;
+a b
+10 Ten
+2 First value
+50 Fifty
+53 Fifty three, was sixty three
+61 Sixty one
+62 Sixty two
+63 Sixty three, new
+64 Sixty four
+SELECT * FROM tp;
+a b
+1 First value
+161 161
+162 162
+163 163
+164 164
+200 Two hundred, end of values
+5 Five
+53 Fifty three, was three
+59 To be deleted
+63 Sixty three, new
+99 End of values
+DROP TABLE t, tp, tsp;
diff --git a/mysql-test/suite/parts/r/partition_exchange_myisam.result b/mysql-test/suite/parts/r/partition_exchange_myisam.result
new file mode 100644
index 00000000000..932891d74fa
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_exchange_myisam.result
@@ -0,0 +1,374 @@
+# Test with AUTO_INCREMENT
+CREATE TABLE tp
+(a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+b varchar(24))
+ENGINE = 'MyISAM'
+PARTITION BY HASH (a) PARTITIONS 4;
+CREATE TABLE t LIKE tp;
+ALTER TABLE t REMOVE PARTITIONING;
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY HASH (a)
+PARTITIONS 4 */
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+INSERT INTO tp (b) VALUES ("One"), ("Two"), ("Three"), ("Four"), ("Five"),
+("Six"), ("Seven"), ("Eight"), ("Nine"), ("Ten"), ("Eleven"), ("Twelwe");
+INSERT INTO tp VALUES (97, "Ninety seven");
+INSERT INTO tp VALUES (111, "One hundred eleven");
+INSERT INTO tp VALUES (101, "One hundred one");
+SET INSERT_ID = 13;
+INSERT INTO t (b) VALUES ("Thirteen");
+SET INSERT_ID = 21;
+INSERT INTO t (b) VALUES ("Twenty one");
+SET INSERT_ID = 25;
+INSERT INTO t (b) VALUES ("Twenty five");
+SET INSERT_ID = 55;
+INSERT INTO t (b) VALUES ("Fifty five");
+DELETE FROM tp WHERE a = 111;
+DELETE FROM t WHERE a = 55;
+UPDATE tp SET a = 41 WHERE a = 101;
+UPDATE t SET a = 17 WHERE a = 25;
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+PARTITION_NAME HAVE_ROWS
+p0 YES
+p1 YES
+p2 YES
+p3 YES
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+HAVE_ROWS
+YES
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t;
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp';
+PARTITION_NAME HAVE_ROWS
+p0 YES
+p1 YES
+p2 YES
+p3 YES
+SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't';
+HAVE_ROWS
+YES
+SELECT * FROM tp ORDER BY a;
+a b
+2 Two
+3 Three
+4 Four
+6 Six
+7 Seven
+8 Eight
+10 Ten
+11 Eleven
+12 Twelwe
+13 Thirteen
+17 Twenty five
+21 Twenty one
+SELECT * FROM t ORDER BY a;
+a b
+1 One
+5 Five
+9 Nine
+41 One hundred one
+97 Ninety seven
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM AUTO_INCREMENT=112 DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY HASH (a)
+PARTITIONS 4 */
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL AUTO_INCREMENT,
+ `b` varchar(24) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM AUTO_INCREMENT=102 DEFAULT CHARSET=latin1
+DROP TABLE tp, t;
+CREATE TABLE t
+(a INT,
+b VARCHAR(55),
+PRIMARY KEY (a))
+ENGINE = 'MyISAM';
+CREATE TABLE tp
+(a INT,
+b VARCHAR(55),
+PRIMARY KEY (a))
+ENGINE = 'MyISAM'
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100),
+PARTITION p1 VALUES LESS THAN MAXVALUE);
+CREATE TABLE tsp
+(a INT,
+b VARCHAR(55),
+PRIMARY KEY (a))
+ENGINE = 'MyISAM'
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (100)
+(SUBPARTITION sp0,
+SUBPARTITION sp1),
+PARTITION p1 VALUES LESS THAN MAXVALUE
+(SUBPARTITION sp2,
+SUBPARTITION sp3));
+INSERT INTO t VALUES (1, "First value"), (3, "Three"), (5, "Five"), (99, "End of values");
+INSERT INTO tp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+INSERT INTO tsp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
+SELECT * FROM t;
+a b
+1 First value
+3 Three
+5 Five
+99 End of values
+SELECT * FROM tp;
+a b
+10 Ten
+161 161
+162 162
+163 163
+164 164
+2 First value
+200 Two hundred, end of values
+50 Fifty
+61 Sixty one
+62 Sixty two
+63 Sixty three
+64 Sixty four
+# Start by testing read/write locking
+SET AUTOCOMMIT = 1;
+# con1
+SET DEBUG_SYNC= 'swap_partition_after_compare_tables SIGNAL swap_in_progress WAIT_FOR goto_verification';
+SET DEBUG_SYNC= 'swap_partition_first_row_read SIGNAL swap_in_progress WAIT_FOR goto_wait';
+SET DEBUG_SYNC= 'swap_partition_after_wait SIGNAL swap_in_progress WAIT_FOR goto_rename';
+SET DEBUG_SYNC= 'swap_partition_before_rename SIGNAL swap_in_progress WAIT_FOR test_done';
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+# con default
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM tp WHERE a = 61;
+a b
+61 Sixty one
+# any write (update/delete/insert) into t or tp should fail
+SET SESSION lock_wait_timeout=1;
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'MyISAM';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'MyISAM';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
+SET DEBUG_SYNC= 'now SIGNAL goto_verification';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# select from t and select/update/delete/insert from tp should work
+SELECT * FROM t WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM tp WHERE a = 61;
+a b
+61 Sixty one
+UPDATE tp SET a = 43, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+# any write (update/delete/insert) into t should fail
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'MyISAM';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'MyISAM';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
+SET DEBUG_SYNC= 'now SIGNAL goto_wait';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# Both tables should now be under exclusive lock, even SHOW should fail
+SELECT * FROM t WHERE a = 99;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM tp WHERE a = 61;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE tp;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'MyISAM';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'MyISAM';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SET DEBUG_SYNC= 'now SIGNAL goto_rename';
+SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress';
+# Both tables should now be under exclusive lock
+SELECT * FROM t WHERE a = 99;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SELECT * FROM tp WHERE a = 61;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM tp WHERE a = 59;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+DELETE FROM t WHERE a = 3;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE t ENGINE = 'MyISAM';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+ALTER TABLE tp ENGINE = 'MyISAM';
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE t;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SHOW CREATE TABLE tp;
+ERROR HY000: Lock wait timeout exceeded; try restarting transaction
+SET DEBUG_SYNC= 'now SIGNAL test_done';
+# con1
+# con default
+# Tables should now be as normal
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
+SELECT * FROM tp WHERE a = 99;
+a b
+99 End of values
+SELECT * FROM t WHERE a = 61;
+a b
+61 Sixty one
+UPDATE t SET a = 53, b = "Fifty three, was sixty three" WHERE a = 63;
+INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted");
+DELETE FROM t WHERE a = 59;
+UPDATE tp SET a = 53, b = "Fifty three, was three" WHERE a = 3;
+INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
+DELETE FROM tp WHERE a = 3;
+ALTER TABLE t ENGINE = 'MyISAM';
+ALTER TABLE tp ENGINE = 'MyISAM';
+# con default
+SET DEBUG_SYNC= 'RESET';
+SHOW CREATE TABLE t;
+Table Create Table
+t CREATE TABLE `t` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SHOW CREATE TABLE tp;
+Table Create Table
+tp CREATE TABLE `tp` (
+ `a` int(11) NOT NULL DEFAULT '0',
+ `b` varchar(55) DEFAULT NULL,
+ PRIMARY KEY (`a`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100) ENGINE = MyISAM,
+ PARTITION p1 VALUES LESS THAN MAXVALUE ENGINE = MyISAM) */
+SELECT * FROM t;
+a b
+10 Ten
+2 First value
+50 Fifty
+53 Fifty three, was sixty three
+61 Sixty one
+62 Sixty two
+63 Sixty three, new
+64 Sixty four
+SELECT * FROM tp;
+a b
+1 First value
+161 161
+162 162
+163 163
+164 164
+200 Two hundred, end of values
+5 Five
+53 Fifty three, was three
+59 To be deleted
+63 Sixty three, new
+99 End of values
+DROP TABLE t, tp, tsp;
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result b/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result
index f1889289368..330258094ef 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_archive.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `TableA` (
(PARTITION parta ENGINE = ARCHIVE,
PARTITION partB ENGINE = ARCHIVE,
PARTITION Partc ENGINE = ARCHIVE) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = ARCHIVE,
+ PARTITION partB ENGINE = ARCHIVE,
+ PARTITION Partc ENGINE = ARCHIVE) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `TableB` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = ARCHIVE,
+ PARTITION partB ENGINE = ARCHIVE,
+ PARTITION Partc ENGINE = ARCHIVE) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result b/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result
index da51cb26a1b..5b54e9c571f 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_innodb.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `TableA` (
(PARTITION parta ENGINE = InnoDB,
PARTITION partB ENGINE = InnoDB,
PARTITION Partc ENGINE = InnoDB) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = InnoDB,
+ PARTITION partB ENGINE = InnoDB,
+ PARTITION Partc ENGINE = InnoDB) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `TableB` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = InnoDB,
+ PARTITION partB ENGINE = InnoDB,
+ PARTITION Partc ENGINE = InnoDB) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result b/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result
index 8e8fcfd7672..dd4bed89ea8 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_memory.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `TableA` (
(PARTITION parta ENGINE = MEMORY,
PARTITION partB ENGINE = MEMORY,
PARTITION Partc ENGINE = MEMORY) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MEMORY,
+ PARTITION partB ENGINE = MEMORY,
+ PARTITION Partc ENGINE = MEMORY) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `TableB` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MEMORY,
+ PARTITION partB ENGINE = MEMORY,
+ PARTITION Partc ENGINE = MEMORY) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result b/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result
index 321d10a6a37..b01279017fe 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc0_myisam.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `TableA` (
(PARTITION parta ENGINE = MyISAM,
PARTITION partB ENGINE = MyISAM,
PARTITION Partc ENGINE = MyISAM) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MyISAM,
+ PARTITION partB ENGINE = MyISAM,
+ PARTITION Partc ENGINE = MyISAM) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `TableB` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MyISAM,
+ PARTITION partB ENGINE = MyISAM,
+ PARTITION Partc ENGINE = MyISAM) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc1_archive.result b/mysql-test/suite/parts/r/partition_mgm_lc1_archive.result
index fe33a5bdcd1..66ba08cfbe0 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_archive.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_archive.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `tablea` (
(PARTITION parta ENGINE = ARCHIVE,
PARTITION partB ENGINE = ARCHIVE,
PARTITION Partc ENGINE = ARCHIVE) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `tablea` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = ARCHIVE,
+ PARTITION partB ENGINE = ARCHIVE,
+ PARTITION Partc ENGINE = ARCHIVE) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `tableb` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `tablea` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = ARCHIVE,
+ PARTITION partB ENGINE = ARCHIVE,
+ PARTITION Partc ENGINE = ARCHIVE) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result b/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result
index f2509471e9e..e1c2d0a74bb 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_innodb.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `tablea` (
(PARTITION parta ENGINE = InnoDB,
PARTITION partB ENGINE = InnoDB,
PARTITION Partc ENGINE = InnoDB) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `tablea` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = InnoDB,
+ PARTITION partB ENGINE = InnoDB,
+ PARTITION Partc ENGINE = InnoDB) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `tableb` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `tablea` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = InnoDB,
+ PARTITION partB ENGINE = InnoDB,
+ PARTITION Partc ENGINE = InnoDB) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result b/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result
index c129f70ed4e..ecd89689435 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_memory.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `tablea` (
(PARTITION parta ENGINE = MEMORY,
PARTITION partB ENGINE = MEMORY,
PARTITION Partc ENGINE = MEMORY) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `tablea` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MEMORY,
+ PARTITION partB ENGINE = MEMORY,
+ PARTITION Partc ENGINE = MEMORY) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `tableb` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `tablea` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MEMORY,
+ PARTITION partB ENGINE = MEMORY,
+ PARTITION Partc ENGINE = MEMORY) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result b/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result
index 398c0174a5d..deecf320d7d 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc1_myisam.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `tablea` (
(PARTITION parta ENGINE = MyISAM,
PARTITION partB ENGINE = MyISAM,
PARTITION Partc ENGINE = MyISAM) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `tablea` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MyISAM,
+ PARTITION partB ENGINE = MyISAM,
+ PARTITION Partc ENGINE = MyISAM) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `tableb` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `tablea` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MyISAM,
+ PARTITION partB ENGINE = MyISAM,
+ PARTITION Partc ENGINE = MyISAM) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc2_archive.result b/mysql-test/suite/parts/r/partition_mgm_lc2_archive.result
index d8eef0f0ee2..f3503889699 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_archive.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_archive.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `TableA` (
(PARTITION parta ENGINE = ARCHIVE,
PARTITION partB ENGINE = ARCHIVE,
PARTITION Partc ENGINE = ARCHIVE) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = ARCHIVE,
+ PARTITION partB ENGINE = ARCHIVE,
+ PARTITION Partc ENGINE = ARCHIVE) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `TableB` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=ARCHIVE DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = ARCHIVE,
+ PARTITION partB ENGINE = ARCHIVE,
+ PARTITION Partc ENGINE = ARCHIVE) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result b/mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result
index 8ca72703180..6b737588ba8 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_innodb.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `TableA` (
(PARTITION parta ENGINE = InnoDB,
PARTITION partB ENGINE = InnoDB,
PARTITION Partc ENGINE = InnoDB) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = InnoDB,
+ PARTITION partB ENGINE = InnoDB,
+ PARTITION Partc ENGINE = InnoDB) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `TableB` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = InnoDB,
+ PARTITION partB ENGINE = InnoDB,
+ PARTITION Partc ENGINE = InnoDB) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc2_memory.result b/mysql-test/suite/parts/r/partition_mgm_lc2_memory.result
index 7d44a5ca23f..1a7dd39cbc3 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_memory.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_memory.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `TableA` (
(PARTITION parta ENGINE = MEMORY,
PARTITION partB ENGINE = MEMORY,
PARTITION Partc ENGINE = MEMORY) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MEMORY,
+ PARTITION partB ENGINE = MEMORY,
+ PARTITION Partc ENGINE = MEMORY) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `TableB` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MEMORY DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MEMORY,
+ PARTITION partB ENGINE = MEMORY,
+ PARTITION Partc ENGINE = MEMORY) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result b/mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result
index 7b6b7864711..99fa3e66377 100644
--- a/mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result
+++ b/mysql-test/suite/parts/r/partition_mgm_lc2_myisam.result
@@ -88,6 +88,78 @@ TableA CREATE TABLE `TableA` (
(PARTITION parta ENGINE = MyISAM,
PARTITION partB ENGINE = MyISAM,
PARTITION Partc ENGINE = MyISAM) */
+# Test of EXCHANGE PARTITION WITH TABLE
+SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME TABLE_ROWS
+parta 4
+partB 4
+Partc 4
+CREATE TABLE TableB LIKE TableA;
+ALTER TABLE TableB REMOVE PARTITIONING;
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+12
+2
+3
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MyISAM,
+ PARTITION partB ENGINE = MyISAM,
+ PARTITION Partc ENGINE = MyISAM) */
+SELECT * FROM TableB;
+a
+10
+11
+4
+5
+SHOW CREATE TABLE TableB;
+Table Create Table
+TableB CREATE TABLE `TableB` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA';
+PARTITION_NAME HAVE_TABLE_ROWS
+parta NO
+partB YES
+Partc YES
+ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB;
+INSERT INTO TableB VALUES (11);
+ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB;
+ERROR HY000: Found a row that does not match the partition
+DROP TABLE TableB;
+SELECT * FROM TableA;
+a
+1
+10
+11
+12
+2
+3
+4
+5
+6
+7
+8
+9
+SHOW CREATE TABLE TableA;
+Table Create Table
+TableA CREATE TABLE `TableA` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+/*!50100 PARTITION BY KEY (a)
+(PARTITION parta ENGINE = MyISAM,
+ PARTITION partB ENGINE = MyISAM,
+ PARTITION Partc ENGINE = MyISAM) */
# Test of REORGANIZE PARTITIONS
# Should not work on HASH/KEY
ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO
diff --git a/mysql-test/suite/parts/r/partition_repair_myisam.result b/mysql-test/suite/parts/r/partition_repair_myisam.result
index 1e575d985a9..3652698f634 100644
--- a/mysql-test/suite/parts/r/partition_repair_myisam.result
+++ b/mysql-test/suite/parts/r/partition_repair_myisam.result
@@ -1,4 +1,65 @@
# REPAIR USE_FRM is not implemented for partitioned tables.
+# Test what happens if we exchange a crashed partition with a table
+SHOW VARIABLES LIKE 'myisam_recover_options';
+Variable_name Value
+myisam_recover_options OFF
+CREATE TABLE t (a INT, KEY (a)) ENGINE=MyISAM;
+CREATE TABLE tp (a INT, KEY (a)) ENGINE=MyISAM
+PARTITION BY RANGE (a)
+(PARTITION pCrashed VALUES LESS THAN (15),
+PARTITION pMAX VALUES LESS THAN MAXVALUE);
+INSERT INTO t VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
+INSERT INTO tp VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
+FLUSH TABLES;
+# replacing tp#P#pCrashed.MYI with a corrupt + unclosed one created by doing:
+# 'create table t1 (a int key(a))' head -c1024 t1.MYI > corrupt_t1.MYI
+CHECK TABLE tp;
+Table Op Msg_type Msg_text
+test.tp check warning 1 client is using or hasn't closed the table properly
+test.tp check error Size of indexfile is: 1024 Should be: 2048
+test.tp check warning Size of datafile is: 77 Should be: 7
+test.tp check error Partition pCrashed returned error
+test.tp check error Corrupt
+ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
+ERROR HY000: Table './test/tp#P#pCrashed' is marked as crashed and should be repaired
+REPAIR TABLE tp;
+Table Op Msg_type Msg_text
+test.tp repair warning Number of rows changed from 1 to 11
+test.tp repair status OK
+CHECK TABLE tp;
+Table Op Msg_type Msg_text
+test.tp check status OK
+ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
+CHECK TABLE t;
+Table Op Msg_type Msg_text
+test.t check status OK
+CHECK TABLE tp;
+Table Op Msg_type Msg_text
+test.tp check status OK
+FLUSH TABLES;
+CHECK TABLE t;
+Table Op Msg_type Msg_text
+test.t check warning 1 client is using or hasn't closed the table properly
+test.t check error Size of indexfile is: 1024 Should be: 2048
+test.t check warning Size of datafile is: 77 Should be: 7
+test.t check error Corrupt
+ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
+ERROR HY000: Table './test/t' is marked as crashed and should be repaired
+REPAIR TABLE t;
+Table Op Msg_type Msg_text
+test.t repair warning Number of rows changed from 1 to 11
+test.t repair status OK
+CHECK TABLE t;
+Table Op Msg_type Msg_text
+test.t check status OK
+ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
+CHECK TABLE tp;
+Table Op Msg_type Msg_text
+test.tp check status OK
+CHECK TABLE t;
+Table Op Msg_type Msg_text
+test.t check status OK
+DROP TABLE t, tp;
# test of non partitioned myisam for reference
CREATE TABLE t1_will_crash (a INT, KEY (a)) ENGINE=MyISAM;
INSERT INTO t1_will_crash VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
diff --git a/mysql-test/suite/parts/t/partition_debug.test b/mysql-test/suite/parts/t/partition_debug.test
new file mode 100644
index 00000000000..aa943e5fbe1
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_debug.test
@@ -0,0 +1,33 @@
+# Partitioning test that require debug features
+# including crashing tests.
+
+--source include/have_debug.inc
+--source include/have_partition.inc
+# Don't test this under valgrind, memory leaks will occur
+--source include/not_valgrind.inc
+# Crash tests don't work with embedded
+--source include/not_embedded.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+--let $DATADIR= `SELECT @@datadir;`
+
+--echo #
+--echo # WL#4445: EXCHANGE PARTITION WITH TABLE
+--echo # Verify ddl_log in case of crashing.
+call mtr.add_suppression("Attempting backtrace. You can use the following information to find out");
+call mtr.add_suppression('InnoDB: The log sequence numbers [0-9]+ and [0-9]+ in ibdata files do not match the log sequence number [0-9]+ in the ib_logfiles!');
+
+let $create_statement= CREATE TABLE t1 (a INT, b VARCHAR(64)) PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+ PARTITION p1 VALUES LESS THAN MAXVALUE);
+let $insert_statement= 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"), (21, "Original from partition p1"), (22, "Original from partition p1"), (23, "Original from partition p1"), (24, "Original from partition p1");
+
+let $create_statement2= CREATE TABLE t2 (a INT, b VARCHAR(64));
+let $insert_statement2= INSERT INTO t2 VALUES (5, "Original from table t2"), (6, "Original from table t2"), (7, "Original from table t2"), (8, "Original from table t2");
+let $crash_statement= ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
+--source suite/parts/inc/partition_crash_exchange.inc
+let $fail_statement= $crash_statement;
+--source suite/parts/inc/partition_fail_exchange.inc
diff --git a/mysql-test/suite/parts/t/partition_exch_innodb.test b/mysql-test/suite/parts/t/partition_exch_innodb.test
new file mode 100644
index 00000000000..cb666a426bd
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_innodb.test
@@ -0,0 +1,12 @@
+# Author: Horst Hunger
+# Created: 2010-07-05
+
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+let $engine_table= InnoDB;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+--source suite/parts/inc/part_exch_qa.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_myisam.test b/mysql-test/suite/parts/t/partition_exch_myisam.test
new file mode 100644
index 00000000000..c768040959f
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_myisam.test
@@ -0,0 +1,11 @@
+# Author: Horst Hunger
+# Created: 2010-07-05
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+--source suite/parts/inc/part_exch_qa.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_myisam_innodb.test b/mysql-test/suite/parts/t/partition_exch_myisam_innodb.test
new file mode 100644
index 00000000000..fa956f19aec
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_myisam_innodb.test
@@ -0,0 +1,21 @@
+# Author: Horst Hunger
+# Created: 2010-07-05
+
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+--error 1497
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa.test b/mysql-test/suite/parts/t/partition_exch_qa.test
new file mode 100644
index 00000000000..c768040959f
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa.test
@@ -0,0 +1,11 @@
+# Author: Horst Hunger
+# Created: 2010-07-05
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+--source suite/parts/inc/part_exch_qa.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_10.test b/mysql-test/suite/parts/t/partition_exch_qa_10.test
new file mode 100644
index 00000000000..4f569605f5f
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_10.test
@@ -0,0 +1,69 @@
+# Author: Horst Hunger
+# Created: 2010-07-13
+
+--source include/not_embedded.inc
+--source include/have_partition.inc
+--source include/have_innodb.inc
+
+let $engine_table= InnoDB;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+# 17) Exchanges in Procedure, triggers and events.
+DELIMITER |;
+CREATE PROCEDURE test_p1 ()
+BEGIN
+ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a);
+ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a);
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+ALTER TABLE tp DROP INDEX a;
+ALTER TABLE t_10 DROP INDEX a;
+END|
+DELIMITER ;|
+CALL test_p1;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 9;
+DROP PROCEDURE test_p1;
+
+SET @save_autocommit= @@autocommit;
+SET @@autocommit= OFF;
+SHOW VARIABLES LIKE '%autocommit%';
+DELIMITER |;
+--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
+CREATE TRIGGER test_trg_1 BEFORE UPDATE ON tp FOR EACH ROW
+BEGIN
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+END|
+--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG
+CREATE FUNCTION test_f_1() RETURNS int
+BEGIN
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+END|
+DELIMITER ;|
+SET @@autocommit= @save_autocommit;
+
+SET @save_event_scheduler= @@global.event_scheduler;
+SET @@global.event_scheduler= ON;
+CREATE EVENT test_ev_1
+ ON SCHEDULE AT CURRENT_TIMESTAMP
+ DO
+ ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+sleep 1;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 9;
+SET @@global.event_scheduler= @save_event_scheduler;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_11.test b/mysql-test/suite/parts/t/partition_exch_qa_11.test
new file mode 100644
index 00000000000..3283c65966b
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_11.test
@@ -0,0 +1,37 @@
+# Author: Horst Hunger
+# Created: 2010-07-13
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+# 13) Exchange with dynamic variables.
+SET @part= 'p0';
+SET @part_tab= 'tp';
+SET @table= 't_10';
+SET @s= CONCAT('ALTER TABLE ',@part_tab,' EXCHANGE PARTITION ',@part,' WITH TABLE ',@table);
+PREPARE test_stmt1 FROM @s;
+EXECUTE test_stmt1;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp;
+DEALLOCATE PREPARE test_stmt1;
+
+SET @part_tab= 'tp';
+SET @s= CONCAT('ALTER TABLE ',@part_tab,' EXCHANGE PARTITION ? WITH TABLE ?');
+--error ER_PARSE_ERROR
+PREPARE test_stmt2 FROM @s;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_12.test b/mysql-test/suite/parts/t/partition_exch_qa_12.test
new file mode 100644
index 00000000000..7e048f79017
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_12.test
@@ -0,0 +1,178 @@
+# Author: Horst Hunger
+# Created: 2010-07-13
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--disable_warnings
+DROP TABLE IF EXISTS t_10;
+DROP TABLE IF EXISTS t_100;
+DROP TABLE IF EXISTS t_1000;
+DROP TABLE IF EXISTS tp;
+DROP TABLE IF EXISTS tsp;
+DROP TABLE IF EXISTS t_empty;
+DROP TABLE IF EXISTS t_null;
+--enable_warnings
+
+eval CREATE TABLE t_10 (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+CHECKSUM= 1,
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_100 (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+COMMENT= 'comment',
+ROW_FORMAT= COMPRESSED,
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_1000 (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+MIN_ROWS= 1,
+MAX_ROWS= 200,
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_empty (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = $engine_table;
+
+eval CREATE TABLE t_null (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = $engine_table;
+
+eval CREATE TABLE tp (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = $engine_part
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (10),
+ PARTITION p1 VALUES LESS THAN (100),
+ PARTITION p2 VALUES LESS THAN (1000));
+
+eval CREATE TABLE tsp (a INT,
+ b VARCHAR(55),
+ PRIMARY KEY (a))
+ENGINE = $engine_subpart
+PARTITION BY RANGE (a)
+SUBPARTITION BY HASH(a)
+(PARTITION p0 VALUES LESS THAN (10)
+ (SUBPARTITION sp00,
+ SUBPARTITION sp01,
+ SUBPARTITION sp02,
+ SUBPARTITION sp03,
+ SUBPARTITION sp04),
+ PARTITION p1 VALUES LESS THAN (100)
+ (SUBPARTITION sp10,
+ SUBPARTITION sp11,
+ SUBPARTITION sp12,
+ SUBPARTITION sp13,
+ SUBPARTITION sp14),
+ PARTITION p2 VALUES LESS THAN (1000)
+ (SUBPARTITION sp20,
+ SUBPARTITION sp21,
+ SUBPARTITION sp22,
+ SUBPARTITION sp23,
+ SUBPARTITION sp24));
+
+# Values t_10 (not partitioned)
+INSERT INTO t_10 VALUES (1, "One"), (3, "Three"), (5, "Five"), (9, "Nine");
+
+# Values t_100 (not partitioned)
+INSERT INTO t_100 VALUES (11, "Eleven"), (13, "Thirdteen"), (15, "Fifeteen"), (19, "Nineteen");
+INSERT INTO t_100 VALUES (91, "Ninety-one"), (93, "Ninety-three"), (95, "Ninety-five"), (99, "Ninety-nine");
+
+# Values t_1000 (not partitioned)
+INSERT INTO t_1000 VALUES (111, "Hundred elven"), (113, "Hundred thirdteen"), (115, "Hundred fiveteen"), (119, "Hundred nineteen");
+INSERT INTO t_1000 VALUES (131, "Hundred thirty-one"), (133, "Hundred thirty-three"), (135, "Hundred thirty-five"), (139, "Hundred thirty-nine");
+INSERT INTO t_1000 VALUES (151, "Hundred fifty-one"), (153, "Hundred fifty-three"), (155, "Hundred fity-five"), (159, "Hundred fifty-nine");
+INSERT INTO t_1000 VALUES (191, "Hundred ninety-one"), (193, "Hundred ninety-three"), (195, "Hundred ninety-five"), (199, "Hundred ninety-nine");
+
+# Values t_null (not partitioned)
+INSERT INTO t_null VALUES (1, "NULL");
+
+# Values tp (partitions)
+INSERT INTO tp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight");
+INSERT INTO tp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen");
+INSERT INTO tp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen");
+INSERT INTO tp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight");
+INSERT INTO tp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight");
+INSERT INTO tp VALUES (182, "Hundred eighty-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight");
+
+# Values tps (subpartitions)
+INSERT INTO tsp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight");
+INSERT INTO tsp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen");
+INSERT INTO tsp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen");
+INSERT INTO tsp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight");
+INSERT INTO tsp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight");
+INSERT INTO tsp VALUES (182, "Hundred eight-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight");
+
+eval CREATE TABLE tsp_01(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 1;
+eval CREATE TABLE tsp_02(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 2;
+eval CREATE TABLE tsp_03(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 3;
+eval CREATE TABLE tsp_04(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 4;
+eval CREATE TABLE tsp_00(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table
+ AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 0;
+
+SHOW CREATE TABLE t_10;
+SHOW CREATE TABLE t_100;
+SHOW CREATE TABLE t_1000;
+SHOW CREATE TABLE tp;
+SHOW CREATE TABLE tsp;
+
+--enable_result_log
+--enable_query_log
+
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM t_100;
+--sorted_result
+SELECT * FROM t_1000;
+--sorted_result
+SELECT * FROM tp;
+--sorted_result
+SELECT * FROM tsp;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp_01;
+--sorted_result
+SELECT * FROM tsp_02;
+--sorted_result
+SELECT * FROM tsp_03;
+--sorted_result
+SELECT * FROM tsp_04;
+
+# 13) Exchanges with different table options.
+# IGNORE was removed in bug#57708.
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+#--error ER_TABLES_DIFFERENT_METADATA
+#ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10 IGNORE;
+SELECT TABLE_NAME, ROW_FORMAT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'test'
+AND TABLE_NAME IN ('tp', 't_100');
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100;
+#--error ER_TABLES_DIFFERENT_METADATA
+#ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100 IGNORE;
+--error ER_PARTITION_EXCHANGE_DIFFERENT_OPTION
+ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_1000;
+#--error ER_PARTITION_EXCHANGE_DIFFERENT_OPTION
+#ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_1000 IGNORE;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_13.test b/mysql-test/suite/parts/t/partition_exch_qa_13.test
new file mode 100644
index 00000000000..c830ee61dad
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_13.test
@@ -0,0 +1,11 @@
+# Author: Horst Hunger
+# Created: 2010-07-13
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+--source suite/parts/inc/part_exch_qa_13.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_14.test b/mysql-test/suite/parts/t/partition_exch_qa_14.test
new file mode 100644
index 00000000000..7c6699a0a72
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_14.test
@@ -0,0 +1,94 @@
+# Author: Horst Hunger
+# Created: 2010-07-13
+
+--source include/not_windows.inc
+--source include/have_partition.inc
+--source include/have_symlink.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+# DATA DIRECTORY
+# Make directory for partition data
+let $data_dir_path= $MYSQLTEST_VARDIR/mysql-test-data-dir;
+--mkdir $data_dir_path
+let $p_data_directory= DATA DIRECTORY = '$data_dir_path';
+let $data_directory= DATA DIRECTORY = '$data_dir_path';
+
+# INDEX DIRECTORY
+# Make directory for partition index
+let $idx_dir_path= $MYSQLTEST_VARDIR/mysql-test-idx-dir;
+--mkdir $idx_dir_path
+let $p_index_directory= INDEX DIRECTORY = '$idx_dir_path';
+let $index_directory= INDEX DIRECTORY = '$idx_dir_path';
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+--rmdir $data_dir_path
+--rmdir $idx_dir_path
+
+# DATA DIRECTORY
+# Make directory for partition data
+let $data_dir_path= $MYSQLTEST_VARDIR/mysql-test-data-dir;
+--mkdir $data_dir_path
+let $p_data_directory= DATA DIRECTORY = '$data_dir_path';
+
+# INDEX DIRECTORY
+# Make directory for partition index
+let $idx_dir_path= $MYSQLTEST_VARDIR/mysql-test-idx-dir;
+--mkdir $idx_dir_path
+let $p_index_directory= INDEX DIRECTORY = '$idx_dir_path';
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+--rmdir $data_dir_path
+--rmdir $idx_dir_path
+
+# DATA DIRECTORY
+# Make directory for partition data
+let $data_dir_path= $MYSQLTEST_VARDIR/mysql-test-data-dir;
+--mkdir $data_dir_path
+let $data_directory= DATA DIRECTORY = '$data_dir_path';
+
+# INDEX DIRECTORY
+# Make directory for partition index
+let $idx_dir_path= $MYSQLTEST_VARDIR/mysql-test-idx-dir;
+--mkdir $idx_dir_path
+let $index_directory= INDEX DIRECTORY = '$idx_dir_path';
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+--rmdir $data_dir_path
+--rmdir $idx_dir_path
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_15.test b/mysql-test/suite/parts/t/partition_exch_qa_15.test
new file mode 100644
index 00000000000..51d09be5ed9
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_15.test
@@ -0,0 +1,31 @@
+# Author: Horst Hunger
+# Created: 2010-07-15
+
+--source include/have_innodb.inc
+--source include/have_partition.inc
+
+let $engine_table= InnoDB;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+# 21) Foreign Key.
+# Exchange of partition with table differing in structure.
+CREATE TABLE t_11 (a INT, b VARCHAR(55),
+ FOREIGN KEY (a) REFERENCES t_10 (a) ON DELETE CASCADE)
+ ENGINE= InnoDB;
+#--error ER_TABLES_DIFFERENT_METADATA
+--error ER_PARTITION_EXCHANGE_FOREIGN_KEY
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+--disable_warnings
+DROP TABLE IF EXISTS t_11;
+--enable_warnings
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_1_innodb.test b/mysql-test/suite/parts/t/partition_exch_qa_1_innodb.test
new file mode 100644
index 00000000000..210791515dc
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_1_innodb.test
@@ -0,0 +1,12 @@
+# Author: Horst Hunger
+# Created: 2010-07-13
+
+--source include/have_partition.inc
+--source include/have_innodb.inc
+
+let $engine_table= InnoDB;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+--source suite/parts/inc/part_exch_qa_1.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_1_myisam.test b/mysql-test/suite/parts/t/partition_exch_qa_1_myisam.test
new file mode 100644
index 00000000000..db3a428b01b
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_1_myisam.test
@@ -0,0 +1,11 @@
+# Author: Horst Hunger
+# Created: 2010-07-13
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+--source suite/parts/inc/part_exch_qa_1.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_2.test b/mysql-test/suite/parts/t/partition_exch_qa_2.test
new file mode 100644
index 00000000000..83dc0a81fca
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_2.test
@@ -0,0 +1,80 @@
+# Author: Horst Hunger
+# Created: 2010-07-05
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM t_100;
+--sorted_result
+SELECT * FROM t_1000;
+--sorted_result
+SELECT * FROM tp;
+--sorted_result
+SELECT * FROM tsp;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp_01;
+--sorted_result
+SELECT * FROM tsp_02;
+--sorted_result
+SELECT * FROM tsp_03;
+--sorted_result
+SELECT * FROM tsp_04;
+
+# 3) Invalid exchanges.
+# Exchange of partition with table differing in structure.
+CREATE TABLE t_11(a INT,b VARCHAR(55)) SELECT * FROM t_10;
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+--disable_warnings
+DROP TABLE IF EXISTS t_11;
+--enable_warnings
+eval CREATE TABLE t_11(a INT,b CHAR(55),PRIMARY KEY(a)) ENGINE= $engine_table SELECT * FROM t_10;
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+--disable_warnings
+DROP TABLE IF EXISTS t_11;
+CREATE TABLE t_11(a INT,b VARCHAR(55),PRIMARY KEY(a)) ENGINE= MEMORY SELECT * FROM t_10;
+--error ER_MIX_HANDLER_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+--disable_warnings
+DROP TABLE IF EXISTS t_11;
+--enable_warnings
+# Exchange of partition with partitioned table.
+eval CREATE TABLE t_11(a INT,b CHAR(55),PRIMARY KEY(a)) ENGINE= $engine_table
+ PARTITION BY KEY() AS SELECT * FROM t_10;
+--error ER_PARTITION_EXCHANGE_PART_TABLE
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_11;
+--disable_warnings
+DROP TABLE IF EXISTS t_11;
+--enable_warnings
+# Exchange of subpartition with partitioned table.
+--error ER_PARTITION_EXCHANGE_PART_TABLE
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE tsp;
+# Exchange of subpartitioned partition with table.
+--error ER_PARTITION_INSTEAD_OF_SUBPARTITION
+ALTER TABLE tsp EXCHANGE PARTITION p0 WITH TABLE t_10;
+# Exchange of values in partition not fitting the hash.
+--error ER_ROW_DOES_NOT_MATCH_PARTITION
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_100;
+# Exchange of values in subpartition not fitting the hash.
+--error ER_ROW_DOES_NOT_MATCH_PARTITION
+ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_10;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_3.test b/mysql-test/suite/parts/t/partition_exch_qa_3.test
new file mode 100644
index 00000000000..aa79e97adb6
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_3.test
@@ -0,0 +1,47 @@
+# Author: Horst Hunger
+# Created: 2010-07-05
+
+--source include/have_partition.inc
+--source include/have_innodb.inc
+
+let $engine_table= MYISAM;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+use test;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM t_100;
+--sorted_result
+SELECT * FROM t_1000;
+--sorted_result
+SELECT * FROM tp;
+--sorted_result
+SELECT * FROM tsp;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp_01;
+--sorted_result
+SELECT * FROM tsp_02;
+--sorted_result
+SELECT * FROM tsp_03;
+--sorted_result
+SELECT * FROM tsp_04;
+--enable_result_log
+--enable_query_log
+
+# 5) Exchanges with different engines.
+--error ER_MIX_HANDLER_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--error ER_MIX_HANDLER_ERROR
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_4_innodb.test b/mysql-test/suite/parts/t/partition_exch_qa_4_innodb.test
new file mode 100644
index 00000000000..ea38337f3aa
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_4_innodb.test
@@ -0,0 +1,12 @@
+# Author: Horst Hunger
+# Created: 2010-07-06
+
+--source include/have_partition.inc
+--source include/have_innodb.inc
+
+let $engine_table= InnoDB;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+--source suite/parts/inc/part_exch_qa_4.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_4_myisam.test b/mysql-test/suite/parts/t/partition_exch_qa_4_myisam.test
new file mode 100644
index 00000000000..f668164630b
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_4_myisam.test
@@ -0,0 +1,11 @@
+# Author: Horst Hunger
+# Created: 2010-07-06
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+--source suite/parts/inc/part_exch_qa_4.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_5_innodb.test b/mysql-test/suite/parts/t/partition_exch_qa_5_innodb.test
new file mode 100644
index 00000000000..b1daa070412
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_5_innodb.test
@@ -0,0 +1,12 @@
+# Author: Horst Hunger
+# Created: 2010-07-06
+
+--source include/have_partition.inc
+--source include/have_innodb.inc
+
+let $engine_table= InnoDB;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+--source suite/parts/inc/part_exch_qa_5.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_5_myisam.test b/mysql-test/suite/parts/t/partition_exch_qa_5_myisam.test
new file mode 100644
index 00000000000..8fcf43b8148
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_5_myisam.test
@@ -0,0 +1,11 @@
+# Author: Horst Hunger
+# Created: 2010-07-06
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+--source suite/parts/inc/part_exch_qa_5.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_6.test b/mysql-test/suite/parts/t/partition_exch_qa_6.test
new file mode 100644
index 00000000000..bad1e134af7
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_6.test
@@ -0,0 +1,102 @@
+# Author: Horst Hunger
+# Created: 2010-07-06
+
+--source include/not_embedded.inc
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+CREATE USER test2@localhost;
+
+--disable_result_log
+--disable_query_log
+--source suite/parts/inc/part_exch_tabs.inc
+--enable_result_log
+--enable_query_log
+
+GRANT USAGE ON *.* TO test2@localhost;
+GRANT CREATE, DROP, ALTER, UPDATE, INSERT, SELECT ON test.* TO test2@localhost;
+
+--echo connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+USE test;
+SHOW GRANTS FOR CURRENT_USER;
+# 9) Exchanges with different owner.
+# Privilege for ALTER and SELECT
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+# Back to former values.
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--sorted_result
+SELECT * FROM t_10;
+--sorted_result
+SELECT * FROM tp WHERE a BETWEEN 0 AND 10;
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+# Back to former values.
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+--sorted_result
+SELECT * FROM tsp_00;
+--sorted_result
+SELECT * FROM tsp WHERE a BETWEEN 0 AND 10;
+--echo disconnect test2;
+disconnect test2;
+
+--echo connection default;
+connection default;
+REVOKE INSERT ON test.* FROM test2@localhost;
+
+--echo connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+USE test;
+SHOW GRANTS FOR CURRENT_USER;
+# Privilege for ALTER and SELECT
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--echo disconnect test2;
+disconnect test2;
+
+--echo connection default;
+connection default;
+GRANT INSERT ON test.* TO test2@localhost;
+REVOKE CREATE ON test.* FROM test2@localhost;
+
+--echo connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+USE test;
+SHOW GRANTS FOR CURRENT_USER;
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00;
+--echo disconnect test2;
+disconnect test2;
+
+--echo connection default;
+connection default;
+GRANT CREATE ON test.* TO test2@localhost;
+REVOKE DROP ON test.* FROM test2@localhost;
+
+--echo connect (test2,localhost,test2,,test,MASTER_MYPORT,MASTER_MYSOCK);
+connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
+USE test;
+SHOW GRANTS FOR CURRENT_USER;
+# Privilege for ALTER and SELECT
+--error ER_TABLEACCESS_DENIED_ERROR
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10;
+--echo disconnect test2;
+disconnect test2;
+
+--echo connection default;
+connection default;
+
+--source suite/parts/inc/part_exch_drop_tabs.inc
+
+DROP USER test2@localhost;
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_7_innodb.test b/mysql-test/suite/parts/t/partition_exch_qa_7_innodb.test
new file mode 100644
index 00000000000..e23790672ab
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_7_innodb.test
@@ -0,0 +1,12 @@
+# Author: Horst Hunger
+# Created: 2010-07-06
+
+--source include/have_partition.inc
+--source include/have_innodb.inc
+
+let $engine_table= InnoDB;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+--source suite/parts/inc/part_exch_qa_7.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_7_myisam.test b/mysql-test/suite/parts/t/partition_exch_qa_7_myisam.test
new file mode 100644
index 00000000000..e1bbd2b5815
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_7_myisam.test
@@ -0,0 +1,11 @@
+# Author: Horst Hunger
+# Created: 2010-07-06
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+--source suite/parts/inc/part_exch_qa_7.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_8_innodb.test b/mysql-test/suite/parts/t/partition_exch_qa_8_innodb.test
new file mode 100644
index 00000000000..58fecdbc66d
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_8_innodb.test
@@ -0,0 +1,12 @@
+# Author: Horst Hunger
+# Created: 2010-07-07
+
+--source include/have_partition.inc
+--source include/have_innodb.inc
+
+let $engine_table= InnoDB;
+let $engine_part= InnoDB;
+let $engine_subpart= InnoDB;
+
+--source suite/parts/inc/part_exch_qa_8.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exch_qa_8_myisam.test b/mysql-test/suite/parts/t/partition_exch_qa_8_myisam.test
new file mode 100644
index 00000000000..b8573a6aabf
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exch_qa_8_myisam.test
@@ -0,0 +1,11 @@
+# Author: Horst Hunger
+# Created: 2010-07-07
+
+--source include/have_partition.inc
+
+let $engine_table= MYISAM;
+let $engine_part= MYISAM;
+let $engine_subpart= MYISAM;
+
+--source suite/parts/inc/part_exch_qa_8.inc
+
diff --git a/mysql-test/suite/parts/t/partition_exchange_archive.test b/mysql-test/suite/parts/t/partition_exchange_archive.test
new file mode 100644
index 00000000000..3376e2ff884
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exchange_archive.test
@@ -0,0 +1,11 @@
+--source include/have_archive.inc
+--source include/have_partition.inc
+--source include/have_debug_sync.inc
+
+
+--echo # Archive does not support keys, update or delete
+let $engine= 'Archive';
+let $no_keys= 1;
+let $no_update= 1;
+let $no_delete= 1;
+--source suite/parts/inc/partition_exchange.inc
diff --git a/mysql-test/suite/parts/t/partition_exchange_blackhole.test b/mysql-test/suite/parts/t/partition_exchange_blackhole.test
new file mode 100644
index 00000000000..e58bccfb1a8
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exchange_blackhole.test
@@ -0,0 +1,18 @@
+--source include/have_blackhole.inc
+--source include/have_partition.inc
+--source include/have_debug_sync.inc
+
+let $engine= 'Blackhole';
+--echo # Blackhole has not implemented check_if_incompatible_data,
+--echo # so it cannot support EXCHANGE PARTITION
+CREATE TABLE t (a int, b varchar(55)) ENGINE = 'Blackhole';
+CREATE TABLE tp (a int, b varchar(55)) ENGINE = 'Blackhole'
+PARTITION BY RANGE (a)
+(PARTITION p0 VALUES LESS THAN (100),
+ PARTITION p1 VALUES LESS THAN MAXVALUE);
+--error ER_TABLES_DIFFERENT_METADATA
+ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t;
+DROP TABLE t, tp;
+
+# to use when check_if_incompatible_data is implemented in ha_blackhole
+#--source suite/parts/inc/partition_exchange.inc
diff --git a/mysql-test/suite/parts/t/partition_exchange_innodb.test b/mysql-test/suite/parts/t/partition_exchange_innodb.test
new file mode 100644
index 00000000000..31ea61bbb7b
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exchange_innodb.test
@@ -0,0 +1,6 @@
+--source include/have_innodb.inc
+--source include/have_partition.inc
+--source include/have_debug_sync.inc
+
+let $engine= 'InnoDB';
+--source suite/parts/inc/partition_exchange.inc
diff --git a/mysql-test/suite/parts/t/partition_exchange_memory.test b/mysql-test/suite/parts/t/partition_exchange_memory.test
new file mode 100644
index 00000000000..7384a49f829
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exchange_memory.test
@@ -0,0 +1,5 @@
+--source include/have_partition.inc
+--source include/have_debug_sync.inc
+
+let $engine= 'Memory';
+--source suite/parts/inc/partition_exchange.inc
diff --git a/mysql-test/suite/parts/t/partition_exchange_myisam.test b/mysql-test/suite/parts/t/partition_exchange_myisam.test
new file mode 100644
index 00000000000..68e55090a9c
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_exchange_myisam.test
@@ -0,0 +1,5 @@
+--source include/have_partition.inc
+--source include/have_debug_sync.inc
+
+let $engine= 'MyISAM';
+--source suite/parts/inc/partition_exchange.inc
diff --git a/mysql-test/suite/parts/t/partition_repair_myisam.test b/mysql-test/suite/parts/t/partition_repair_myisam.test
index 91c8ed57580..f7c503a8544 100644
--- a/mysql-test/suite/parts/t/partition_repair_myisam.test
+++ b/mysql-test/suite/parts/t/partition_repair_myisam.test
@@ -5,6 +5,8 @@
drop table if exists t1_will_crash;
call mtr.add_suppression("Got an error from thread_id=.*ha_myisam.cc:");
call mtr.add_suppression("MySQL thread id .*, query id .* localhost.*root Checking table");
+call mtr.add_suppression("is marked as crashed and should be repaired");
+
--enable_query_log
--enable_warnings
@@ -12,6 +14,43 @@ call mtr.add_suppression("MySQL thread id .*, query id .* localhost.*root Checki
let $MYSQLD_DATADIR= `select @@datadir`;
+--echo # Test what happens if we exchange a crashed partition with a table
+SHOW VARIABLES LIKE 'myisam_recover_options';
+CREATE TABLE t (a INT, KEY (a)) ENGINE=MyISAM;
+CREATE TABLE tp (a INT, KEY (a)) ENGINE=MyISAM
+PARTITION BY RANGE (a)
+(PARTITION pCrashed VALUES LESS THAN (15),
+ PARTITION pMAX VALUES LESS THAN MAXVALUE);
+INSERT INTO t VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
+INSERT INTO tp VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);
+FLUSH TABLES;
+--echo # replacing tp#P#pCrashed.MYI with a corrupt + unclosed one created by doing:
+--echo # 'create table t1 (a int key(a))' head -c1024 t1.MYI > corrupt_t1.MYI
+--remove_file $MYSQLD_DATADIR/test/tp#P#pCrashed.MYI
+--copy_file std_data/corrupt_t1.MYI $MYSQLD_DATADIR/test/tp#P#pCrashed.MYI
+CHECK TABLE tp;
+--replace_regex /[^']*test[^']*t/.\/test\/t/
+--error 145
+ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
+REPAIR TABLE tp;
+CHECK TABLE tp;
+ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
+CHECK TABLE t;
+CHECK TABLE tp;
+FLUSH TABLES;
+--remove_file $MYSQLD_DATADIR/test/t.MYI
+--copy_file std_data/corrupt_t1.MYI $MYSQLD_DATADIR/test/t.MYI
+CHECK TABLE t;
+--replace_regex /[^']*test[^']*t/.\/test\/t/
+--error 145
+ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
+REPAIR TABLE t;
+CHECK TABLE t;
+ALTER TABLE tp EXCHANGE PARTITION pCrashed WITH TABLE t;
+CHECK TABLE tp;
+CHECK TABLE t;
+DROP TABLE t, tp;
+
--echo # test of non partitioned myisam for reference
CREATE TABLE t1_will_crash (a INT, KEY (a)) ENGINE=MyISAM;
INSERT INTO t1_will_crash VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11);