diff options
author | Aleksey Midenkov <midenok@gmail.com> | 2021-09-07 20:46:53 +0300 |
---|---|---|
committer | Aleksey Midenkov <midenok@gmail.com> | 2021-09-10 20:09:35 +0300 |
commit | 5b3ed2cad156205d98b31dfd69e9bab5898df046 (patch) | |
tree | cb4b335fd528248c70e210a3fb5062ba92925d42 | |
parent | 90724c78f70160ee042a1f7ef6a12b47fc257cc5 (diff) | |
download | mariadb-git-bb-10.7-midenok-MDEV-22165.tar.gz |
MDEV-22165 CONVERT TABLE: move in partition from existing tablebb-10.7-midenok-MDEV-22165
Syntax for CONVERT TABLE
ALTER TABLE tbl_name
[alter_option [, alter_option] ...] |
[partition_options]
partition_option: {
...
| CONVERT TABLE tbl_name TO PARTITION partition_name partition_spec
}
Examples:
ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 VALUES LESS THAN MAX_VALUE();
New ALTER_PARTITION_CONVERT_IN command for
fast_alter_partition_table() is done in alter_partition_convert_in()
function which basically does ha_rename_table().
Table structure and data check is basically the same as in EXCHANGE
PARTITION command. And these are done by
compare_table_with_partition() and check_table_data().
Atomic DDL is done by the scheme from MDEV-22166 (see the
corresponding commit message). The only differnce is that it also has
to drop source table frm and that is done by WFRM_DROP_CONVERTED_FROM.
-rw-r--r-- | mysql-test/suite/atomic/alter_partition,ib.rdiff | 276 | ||||
-rw-r--r-- | mysql-test/suite/atomic/alter_partition.result | 390 | ||||
-rw-r--r-- | mysql-test/suite/atomic/alter_partition.test | 27 | ||||
-rw-r--r-- | mysql-test/suite/parts/inc/partition_fail_t2.inc | 20 | ||||
-rw-r--r-- | mysql-test/suite/parts/r/alter_table.result | 82 | ||||
-rw-r--r-- | mysql-test/suite/parts/r/partition_debug.result | 1079 | ||||
-rw-r--r-- | mysql-test/suite/parts/r/partition_debug_innodb.result | 252 | ||||
-rw-r--r-- | mysql-test/suite/parts/t/alter_table.test | 67 | ||||
-rw-r--r-- | mysql-test/suite/parts/t/partition_debug.test | 47 | ||||
-rw-r--r-- | sql/handler.h | 6 | ||||
-rw-r--r-- | sql/share/errmsg-utf8.txt | 2 | ||||
-rw-r--r-- | sql/sql_alter.cc | 2 | ||||
-rw-r--r-- | sql/sql_lex.cc | 6 | ||||
-rw-r--r-- | sql/sql_partition.cc | 292 | ||||
-rw-r--r-- | sql/sql_partition.h | 4 | ||||
-rw-r--r-- | sql/sql_partition_admin.cc | 154 | ||||
-rw-r--r-- | sql/sql_table.cc | 4 | ||||
-rw-r--r-- | sql/sql_table.h | 1 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 37 |
19 files changed, 2119 insertions, 629 deletions
diff --git a/mysql-test/suite/atomic/alter_partition,ib.rdiff b/mysql-test/suite/atomic/alter_partition,ib.rdiff index fff7d94eddb..1242c98b3b1 100644 --- a/mysql-test/suite/atomic/alter_partition,ib.rdiff +++ b/mysql-test/suite/atomic/alter_partition,ib.rdiff @@ -1,6 +1,6 @@ --- alter_partition.result +++ alter_partition,ib.reject -@@ -12,12 +12,9 @@ +@@ -17,12 +17,9 @@ end $ # QUERY: ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1 # CRASH: ddl_log_create_before_create_frm @@ -16,7 +16,7 @@ t1.frm t1.par Table Create Table -@@ -33,12 +30,9 @@ +@@ -38,12 +35,9 @@ 12 22 # CRASH: ddl_log_alter_partition_after_create_frm @@ -32,7 +32,7 @@ t1.frm t1.par Table Create Table -@@ -54,12 +48,9 @@ +@@ -59,12 +53,9 @@ 12 22 # CRASH: ddl_log_alter_partition_after_write_frm @@ -48,7 +48,7 @@ t1.frm t1.par Table Create Table -@@ -75,12 +66,9 @@ +@@ -80,12 +71,9 @@ 12 22 # CRASH: crash_convert_partition_1 @@ -64,7 +64,7 @@ t1.frm t1.par Table Create Table -@@ -96,12 +84,9 @@ +@@ -101,12 +89,9 @@ 12 22 # CRASH: crash_convert_partition_2 @@ -80,7 +80,7 @@ t1.frm t1.par Table Create Table -@@ -117,12 +102,9 @@ +@@ -122,12 +107,9 @@ 12 22 # CRASH: crash_convert_partition_3 @@ -96,7 +96,7 @@ t1.frm t1.par Table Create Table -@@ -138,12 +120,9 @@ +@@ -143,12 +125,9 @@ 12 22 # CRASH: crash_convert_partition_4 @@ -112,7 +112,7 @@ t1.frm t1.par Table Create Table -@@ -159,12 +138,9 @@ +@@ -164,12 +143,9 @@ 12 22 # CRASH: crash_convert_partition_5 @@ -128,7 +128,7 @@ t1.frm t1.par Table Create Table -@@ -180,12 +156,9 @@ +@@ -185,12 +161,9 @@ 12 22 # CRASH: crash_convert_partition_6 @@ -144,7 +144,7 @@ t1.frm t1.par Table Create Table -@@ -201,12 +174,9 @@ +@@ -206,12 +179,9 @@ 12 22 # CRASH: crash_convert_partition_7 @@ -160,7 +160,7 @@ t1.frm t1.par Table Create Table -@@ -222,12 +192,9 @@ +@@ -227,12 +197,9 @@ 12 22 # CRASH: crash_convert_partition_8 @@ -176,7 +176,7 @@ t1.frm t1.par Table Create Table -@@ -243,15 +210,12 @@ +@@ -248,15 +215,12 @@ 12 22 # CRASH: crash_convert_partition_9 @@ -195,3 +195,255 @@ master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1 Table Create Table t1 CREATE TABLE `t1` ( +@@ -276,14 +240,10 @@ + 12 + # QUERY: ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) + # NO CRASH: ddl_log_create_before_create_frm +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#p2.MYD +-t1#P#p2.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#p2.ibd ++t1#P#pn.ibd + t1.frm + t1.par + master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) +@@ -303,14 +263,10 @@ + 32 + 39 + # NO CRASH: ddl_log_alter_partition_after_create_frm +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#p2.MYD +-t1#P#p2.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#p2.ibd ++t1#P#pn.ibd + t1.frm + t1.par + master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) +@@ -330,14 +286,10 @@ + 32 + 39 + # NO CRASH: ddl_log_alter_partition_after_write_frm +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#p2.MYD +-t1#P#p2.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#p2.ibd ++t1#P#pn.ibd + t1.frm + t1.par + master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) +@@ -357,17 +309,13 @@ + 32 + 39 + # CRASH: crash_convert_partition_1 +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#pn.ibd + t1.frm + t1.par +-tp2.MYD +-tp2.MYI + tp2.frm ++tp2.ibd + Table Create Table + t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +@@ -388,17 +336,13 @@ + 32 + 39 + # CRASH: crash_convert_partition_2 +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#pn.ibd + t1.frm + t1.par +-tp2.MYD +-tp2.MYI + tp2.frm ++tp2.ibd + Table Create Table + t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +@@ -419,17 +363,13 @@ + 32 + 39 + # CRASH: crash_convert_partition_3 +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#pn.ibd + t1.frm + t1.par +-tp2.MYD +-tp2.MYI + tp2.frm ++tp2.ibd + Table Create Table + t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +@@ -450,17 +390,13 @@ + 32 + 39 + # CRASH: crash_convert_partition_4 +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#pn.ibd + t1.frm + t1.par +-tp2.MYD +-tp2.MYI + tp2.frm ++tp2.ibd + Table Create Table + t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +@@ -481,17 +417,13 @@ + 32 + 39 + # CRASH: crash_convert_partition_5 +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#pn.ibd + t1.frm + t1.par +-tp2.MYD +-tp2.MYI + tp2.frm ++tp2.ibd + Table Create Table + t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +@@ -512,17 +444,13 @@ + 32 + 39 + # CRASH: crash_convert_partition_6 +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#pn.ibd + t1.frm + t1.par +-tp2.MYD +-tp2.MYI + tp2.frm ++tp2.ibd + Table Create Table + t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +@@ -543,17 +471,13 @@ + 32 + 39 + # CRASH: crash_convert_partition_7 +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#pn.ibd + t1.frm + t1.par +-tp2.MYD +-tp2.MYI + tp2.frm ++tp2.ibd + Table Create Table + t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +@@ -574,17 +498,13 @@ + 32 + 39 + # CRASH: crash_convert_partition_8 +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#pn.ibd + t1.frm + t1.par +-tp2.MYD +-tp2.MYI + tp2.frm ++tp2.ibd + Table Create Table + t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +@@ -605,14 +525,10 @@ + 32 + 39 + # CRASH: crash_convert_partition_9 +-t1#P#p0.MYD +-t1#P#p0.MYI +-t1#P#p1.MYD +-t1#P#p1.MYI +-t1#P#p2.MYD +-t1#P#p2.MYI +-t1#P#pn.MYD +-t1#P#pn.MYI ++t1#P#p0.ibd ++t1#P#p1.ibd ++t1#P#p2.ibd ++t1#P#pn.ibd + t1.frm + t1.par + master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) diff --git a/mysql-test/suite/atomic/alter_partition.result b/mysql-test/suite/atomic/alter_partition.result index 32344d7c192..5a43e6fc25e 100644 --- a/mysql-test/suite/atomic/alter_partition.result +++ b/mysql-test/suite/atomic/alter_partition.result @@ -1,13 +1,18 @@ # Crash recovery -create or replace procedure prepare_table() +create or replace procedure prepare_table(r int) begin create or replace table t1 (x int) with system versioning partition by range(x) ( partition p0 values less than (10), partition p1 values less than (20), -partition pn values less than maxvalue); +partition pn values less than (30)); insert into t1 values (2), (12), (22); +if r > 1 then +create or replace table tp2 (x int) +with system versioning; +insert into tp2 values (32), (39); +end if; flush tables; end $ # QUERY: ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1 @@ -27,7 +32,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -48,7 +53,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -69,7 +74,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -90,7 +95,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -111,7 +116,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -132,7 +137,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -153,7 +158,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -174,7 +179,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -195,7 +200,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -216,7 +221,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -237,7 +242,7 @@ t1 CREATE TABLE `t1` ( PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 12 @@ -259,7 +264,7 @@ t1 CREATE TABLE `t1` ( ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING PARTITION BY RANGE (`x`) (PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, - PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = DEFAULT_ENGINE) + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) x 2 22 @@ -269,5 +274,362 @@ tp1 CREATE TABLE `tp1` ( ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING x 12 +# QUERY: ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) +# NO CRASH: ddl_log_create_before_create_frm +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE, + PARTITION `p2` VALUES LESS THAN (40) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +32 +39 +# NO CRASH: ddl_log_alter_partition_after_create_frm +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE, + PARTITION `p2` VALUES LESS THAN (40) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +32 +39 +# NO CRASH: ddl_log_alter_partition_after_write_frm +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE, + PARTITION `p2` VALUES LESS THAN (40) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +32 +39 +# CRASH: crash_convert_partition_1 +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +tp2.MYD +tp2.MYI +tp2.frm +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +Table Create Table +tp2 CREATE TABLE `tp2` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +x +32 +39 +# CRASH: crash_convert_partition_2 +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +tp2.MYD +tp2.MYI +tp2.frm +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +Table Create Table +tp2 CREATE TABLE `tp2` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +x +32 +39 +# CRASH: crash_convert_partition_3 +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +tp2.MYD +tp2.MYI +tp2.frm +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +Table Create Table +tp2 CREATE TABLE `tp2` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +x +32 +39 +# CRASH: crash_convert_partition_4 +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +tp2.MYD +tp2.MYI +tp2.frm +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +Table Create Table +tp2 CREATE TABLE `tp2` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +x +32 +39 +# CRASH: crash_convert_partition_5 +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +tp2.MYD +tp2.MYI +tp2.frm +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +Table Create Table +tp2 CREATE TABLE `tp2` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +x +32 +39 +# CRASH: crash_convert_partition_6 +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +tp2.MYD +tp2.MYI +tp2.frm +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +Table Create Table +tp2 CREATE TABLE `tp2` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +x +32 +39 +# CRASH: crash_convert_partition_7 +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +tp2.MYD +tp2.MYI +tp2.frm +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +Table Create Table +tp2 CREATE TABLE `tp2` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +x +32 +39 +# CRASH: crash_convert_partition_8 +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +tp2.MYD +tp2.MYI +tp2.frm +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +Table Create Table +tp2 CREATE TABLE `tp2` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING +x +32 +39 +# CRASH: crash_convert_partition_9 +t1#P#p0.MYD +t1#P#p0.MYI +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40) +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY RANGE (`x`) +(PARTITION `p0` VALUES LESS THAN (10) ENGINE = DEFAULT_ENGINE, + PARTITION `p1` VALUES LESS THAN (20) ENGINE = DEFAULT_ENGINE, + PARTITION `pn` VALUES LESS THAN (30) ENGINE = DEFAULT_ENGINE, + PARTITION `p2` VALUES LESS THAN (40) ENGINE = DEFAULT_ENGINE) +x +2 +12 +22 +32 +39 Warnings: Note 1051 Unknown table 'test.t1' diff --git a/mysql-test/suite/atomic/alter_partition.test b/mysql-test/suite/atomic/alter_partition.test index 2f0cf71c8a2..5980353e1e8 100644 --- a/mysql-test/suite/atomic/alter_partition.test +++ b/mysql-test/suite/atomic/alter_partition.test @@ -57,22 +57,30 @@ let $crash_points='ddl_log_create_before_create_frm', #let $crash_count= 1; #let $crash_points= 'crash_convert_partition_8'; -let $statement_count= 1; -let $statements= 'ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1'; +let $statement_count= 2; +let $statements= 'ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1', + 'ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40)'; -#let $statement_count=1; -#let $statements='CREATE OR REPLACE TABLE t1 SELECT * from const_table'; +#let $statement_count= 1; +#let $statements= 'ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40)'; --delimiter $ -create or replace procedure prepare_table() +create or replace procedure prepare_table(r int) begin create or replace table t1 (x int) with system versioning partition by range(x) ( partition p0 values less than (10), partition p1 values less than (20), - partition pn values less than maxvalue); + partition pn values less than (30)); insert into t1 values (2), (12), (22); + + if r > 1 then + create or replace table tp2 (x int) + with system versioning; + insert into tp2 values (32), (39); + end if; + flush tables; end $ --delimiter ; @@ -97,7 +105,7 @@ while ($r < $statement_count) let $crash=`select ELT($c, $crash_points)`; --eval set @@default_storage_engine=$default_engine - call prepare_table; + eval call prepare_table($r); if (!$c) { lock tables t1 write; @@ -149,6 +157,11 @@ while ($r < $statement_count) show create table tp1; --error 0, ER_NO_SUCH_TABLE select * from tp1; + --replace_result $default_engine DEFAULT_ENGINE ' PAGE_CHECKSUM=1' '' + --error 0, ER_NO_SUCH_TABLE + show create table tp2; + --error 0, ER_NO_SUCH_TABLE + select * from tp2; # Drop the tables. The warnings will show what was dropped --disable_warnings drop table t1; diff --git a/mysql-test/suite/parts/inc/partition_fail_t2.inc b/mysql-test/suite/parts/inc/partition_fail_t2.inc index 492e6d5a71b..301fb005255 100644 --- a/mysql-test/suite/parts/inc/partition_fail_t2.inc +++ b/mysql-test/suite/parts/inc/partition_fail_t2.inc @@ -2,30 +2,40 @@ # To be used with WL#4445: EXCHANGE PARTITION WITH TABLE. --eval $create_statement2 --eval $insert_statement2 -SHOW CREATE TABLE t2; ---sorted_result -SELECT * FROM t2; --eval $create_statement --eval $insert_statement ---echo # State before failure +--let $dbug_flag= `select @@session.debug_dbug` +--echo # $dbug_flag: BEFORE failure --replace_result #p# #P# +if (!$DATADIR) +{ + --let $DATADIR= `SELECT @@datadir;` +} --list_files $DATADIR/test SHOW CREATE TABLE t1; --sorted_result SELECT * FROM t1; +SHOW CREATE TABLE t2; +--sorted_result +SELECT * FROM t2; # accept all errors --disable_abort_on_error --replace_regex /#sql-exchange-[0-9a-f_\-]*/#sql-exchange/i --eval $fail_statement --enable_abort_on_error ---echo # State after failure +--echo # $dbug_flag: AFTER failure --replace_result #p# #P# --list_files $DATADIR/test SHOW CREATE TABLE t1; --sorted_result SELECT * FROM t1; DROP TABLE t1; +--error 0, ER_NO_SUCH_TABLE SHOW CREATE TABLE t2; --sorted_result +--error 0, ER_NO_SUCH_TABLE SELECT * FROM t2; +# TODO: everything fails with ER_NO_SUCH_TABLE +# but DROP TABLE fails with ER_BAD_TABLE_ERROR! Why? +--error 0, ER_BAD_TABLE_ERROR DROP TABLE t2; diff --git a/mysql-test/suite/parts/r/alter_table.result b/mysql-test/suite/parts/r/alter_table.result index 90085f4876e..4c4d214a401 100644 --- a/mysql-test/suite/parts/r/alter_table.result +++ b/mysql-test/suite/parts/r/alter_table.result @@ -29,7 +29,87 @@ ERROR 42000: Can't open table DROP VIEW v1; DROP TABLE t1, t2; # -# MDEV-22166 MIGRATE PARTITION: move out partition into a table +# MDEV-22165 CONVERT PARTITION: move in partition from existing table +# +create or replace table tp1 (a int); +create or replace table t1 (a int) +partition by hash (a) partitions 2; +alter table t1 convert table tp1 to partition p2; +ERROR HY000: CONVERT TABLE TO PARTITION can only be used on RANGE/LIST partitions +create or replace table t1 (a int) +partition by range (a) +(partition p0 values less than (0)); +alter table t1 convert table non_existent to partition p1 values less than (10); +ERROR 42S02: Table 'test.non_existent' doesn't exist +alter table t1 convert table tp1 to partition p1 values less than (10); +show create table tp1; +ERROR 42S02: Table 'test.tp1' doesn't exist +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=X DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`a`) +(PARTITION `p0` VALUES LESS THAN (0) ENGINE = X, + PARTITION `p1` VALUES LESS THAN (10) ENGINE = X) +create table tp2 (x int); +alter table t1 convert table tp2 to partition p2 values less than (20); +ERROR HY000: Tables have different definitions +show create table tp2; +Table Create Table +tp2 CREATE TABLE `tp2` ( + `x` int(11) DEFAULT NULL +) ENGINE=X DEFAULT CHARSET=latin1 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=X DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`a`) +(PARTITION `p0` VALUES LESS THAN (0) ENGINE = X, + PARTITION `p1` VALUES LESS THAN (10) ENGINE = X) +create or replace table tp2 (a int); +insert tp2 values (1), (15), (17); +alter table t1 convert table tp2 to partition p2 values less than (20); +ERROR HY000: Found a row that does not match the partition +delete from tp2; +insert tp2 values (15), (1), (17); +alter table t1 convert table tp2 to partition p2 values less than (20); +ERROR HY000: Found a row that does not match the partition +delete from tp2; +insert tp2 values (15), (17), (1); +alter table t1 convert table tp2 to partition p2 values less than (20); +ERROR HY000: Found a row that does not match the partition +delete from tp2; +insert tp2 values (15), (17); +alter table t1 convert table tp2 to partition p2 values less than (20); +show create table tp2; +ERROR 42S02: Table 'test.tp2' doesn't exist +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=X DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`a`) +(PARTITION `p0` VALUES LESS THAN (0) ENGINE = X, + PARTITION `p1` VALUES LESS THAN (10) ENGINE = X, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = X) +select * from t1 partition (p2); +a +15 +17 +create or replace table t1 (a int) +partition by range (a) ( +p0 values less than (0), +pn values less than (30)); +insert into t1 values (1); +create or replace table tp1 (a int); +insert into tp1 values (2); +alter table t1 convert table tp1 to partition p1 values less than (10); +ERROR HY000: VALUES LESS THAN value must be strictly increasing for each partition +drop tables t1, tp1; +# +# MDEV-22166 CONVERT PARTITION: move out partition into a table # create or replace table t1 (x int); alter table t1 convert partition p1 to table tp1; diff --git a/mysql-test/suite/parts/r/partition_debug.result b/mysql-test/suite/parts/r/partition_debug.result index c932d637e16..11cc3316463 100644 --- a/mysql-test/suite/parts/r/partition_debug.result +++ b/mysql-test/suite/parts/r/partition_debug.result @@ -1025,23 +1025,11 @@ SET @save_dbug=@@debug_dbug; 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 +# d,exchange_partition_fail_1: BEFORE failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1075,9 +1063,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_1: AFTER failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1129,23 +1129,11 @@ SET SESSION debug_dbug=@save_dbug; 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 +# d,exchange_partition_fail_2: BEFORE failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1179,9 +1167,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_2: AFTER failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1233,23 +1233,11 @@ SET SESSION debug_dbug=@save_dbug; 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 +# d,exchange_partition_fail_3: BEFORE failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1283,9 +1271,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error on rename of './test/t2' to './test/#sql-exchange' (errno: 0 "Internal error/check (Not system error)") -# State after failure +# d,exchange_partition_fail_3: AFTER failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1337,23 +1337,11 @@ SET SESSION debug_dbug=@save_dbug; 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 +# d,exchange_partition_fail_4: BEFORE failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1387,9 +1375,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_4: AFTER failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1441,23 +1441,11 @@ SET SESSION debug_dbug=@save_dbug; 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 +# d,exchange_partition_fail_5: BEFORE failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1491,9 +1479,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +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 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 +# d,exchange_partition_fail_5: AFTER failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1545,23 +1545,11 @@ SET SESSION debug_dbug=@save_dbug; 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 +# d,exchange_partition_fail_6: BEFORE failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1595,9 +1583,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_6: AFTER failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1649,23 +1649,11 @@ SET SESSION debug_dbug=@save_dbug; 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 +# d,exchange_partition_fail_7: BEFORE failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1699,9 +1687,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error on rename of './test/#sql-exchange' to './test/t1#P#p0' (errno: 0 "Internal error/check (Not system error)") -# State after failure +# d,exchange_partition_fail_7: AFTER failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1753,23 +1753,11 @@ SET SESSION debug_dbug=@save_dbug; 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 +# d,exchange_partition_fail_8: BEFORE failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1803,9 +1791,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_8: AFTER failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1857,23 +1857,11 @@ SET SESSION debug_dbug=@save_dbug; 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 +# d,exchange_partition_fail_9: BEFORE failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1907,9 +1895,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_9: AFTER failure db.opt t1#P#p0.MYD t1#P#p0.MYI @@ -1959,7 +1959,832 @@ a b DROP TABLE t2; SET SESSION debug_dbug=@save_dbug; # -# MDEV-22166 MIGRATE PARTITION: move out partition into a table +# MDEV-22165 CONVERT PARTITION: move in partition from existing table +# +set @save_dbug=@@debug_dbug; +set session debug_dbug="+d,fail_convert_partition_1"; +create or replace table t2 (x int primary key); +insert into t2 values (32), (42), (52); +create or replace table t1 (x int primary key) +partition by range(x) ( +partition p1 values less than (10), +partition p2 values less than (20), +partition p3 values less than (30)); +insert into t1 values (2), (12), (22); +# d,fail_convert_partition_1: BEFORE failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +alter table t1 convert table t2 to partition pn values less than maxvalue; +ERROR HY000: Unknown error +# d,fail_convert_partition_1: AFTER failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +DROP TABLE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +DROP TABLE t2; +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_2"; +create or replace table t2 (x int primary key); +insert into t2 values (32), (42), (52); +create or replace table t1 (x int primary key) +partition by range(x) ( +partition p1 values less than (10), +partition p2 values less than (20), +partition p3 values less than (30)); +insert into t1 values (2), (12), (22); +# d,fail_convert_partition_2: BEFORE failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +alter table t1 convert table t2 to partition pn values less than maxvalue; +ERROR HY000: Unknown error +# d,fail_convert_partition_2: AFTER failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +DROP TABLE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +DROP TABLE t2; +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_3"; +create or replace table t2 (x int primary key); +insert into t2 values (32), (42), (52); +create or replace table t1 (x int primary key) +partition by range(x) ( +partition p1 values less than (10), +partition p2 values less than (20), +partition p3 values less than (30)); +insert into t1 values (2), (12), (22); +# d,fail_convert_partition_3: BEFORE failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +alter table t1 convert table t2 to partition pn values less than maxvalue; +ERROR HY000: Unknown error +# d,fail_convert_partition_3: AFTER failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +DROP TABLE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +DROP TABLE t2; +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_4"; +create or replace table t2 (x int primary key); +insert into t2 values (32), (42), (52); +create or replace table t1 (x int primary key) +partition by range(x) ( +partition p1 values less than (10), +partition p2 values less than (20), +partition p3 values less than (30)); +insert into t1 values (2), (12), (22); +# d,fail_convert_partition_4: BEFORE failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +alter table t1 convert table t2 to partition pn values less than maxvalue; +ERROR HY000: Unknown error +# d,fail_convert_partition_4: AFTER failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +DROP TABLE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +DROP TABLE t2; +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_5"; +create or replace table t2 (x int primary key); +insert into t2 values (32), (42), (52); +create or replace table t1 (x int primary key) +partition by range(x) ( +partition p1 values less than (10), +partition p2 values less than (20), +partition p3 values less than (30)); +insert into t1 values (2), (12), (22); +# d,fail_convert_partition_5: BEFORE failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +alter table t1 convert table t2 to partition pn values less than maxvalue; +ERROR HY000: Unknown error +# d,fail_convert_partition_5: AFTER failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +DROP TABLE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +DROP TABLE t2; +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_6"; +create or replace table t2 (x int primary key); +insert into t2 values (32), (42), (52); +create or replace table t1 (x int primary key) +partition by range(x) ( +partition p1 values less than (10), +partition p2 values less than (20), +partition p3 values less than (30)); +insert into t1 values (2), (12), (22); +# d,fail_convert_partition_6: BEFORE failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +alter table t1 convert table t2 to partition pn values less than maxvalue; +ERROR HY000: Unknown error +# d,fail_convert_partition_6: AFTER failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +DROP TABLE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +DROP TABLE t2; +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_7"; +create or replace table t2 (x int primary key); +insert into t2 values (32), (42), (52); +create or replace table t1 (x int primary key) +partition by range(x) ( +partition p1 values less than (10), +partition p2 values less than (20), +partition p3 values less than (30)); +insert into t1 values (2), (12), (22); +# d,fail_convert_partition_7: BEFORE failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +alter table t1 convert table t2 to partition pn values less than maxvalue; +ERROR HY000: Unknown error +# d,fail_convert_partition_7: AFTER failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +DROP TABLE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +DROP TABLE t2; +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_8"; +create or replace table t2 (x int primary key); +insert into t2 values (32), (42), (52); +create or replace table t1 (x int primary key) +partition by range(x) ( +partition p1 values less than (10), +partition p2 values less than (20), +partition p3 values less than (30)); +insert into t1 values (2), (12), (22); +# d,fail_convert_partition_8: BEFORE failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +alter table t1 convert table t2 to partition pn values less than maxvalue; +ERROR HY000: Unknown error +# d,fail_convert_partition_8: AFTER failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +DROP TABLE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +DROP TABLE t2; +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_9"; +create or replace table t2 (x int primary key); +insert into t2 values (32), (42), (52); +create or replace table t1 (x int primary key) +partition by range(x) ( +partition p1 values less than (10), +partition p2 values less than (20), +partition p3 values less than (30)); +insert into t1 values (2), (12), (22); +# d,fail_convert_partition_9: BEFORE failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1.frm +t1.par +t2.MYD +t2.MYI +t2.frm +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +x +32 +42 +52 +alter table t1 convert table t2 to partition pn values less than maxvalue; +# d,fail_convert_partition_9: AFTER failure +db.opt +t1#P#p1.MYD +t1#P#p1.MYI +t1#P#p2.MYD +t1#P#p2.MYI +t1#P#p3.MYD +t1#P#p3.MYI +t1#P#pn.MYD +t1#P#pn.MYI +t1.frm +t1.par +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) NOT NULL, + PRIMARY KEY (`x`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY RANGE (`x`) +(PARTITION `p1` VALUES LESS THAN (10) ENGINE = MyISAM, + PARTITION `p2` VALUES LESS THAN (20) ENGINE = MyISAM, + PARTITION `p3` VALUES LESS THAN (30) ENGINE = MyISAM, + PARTITION `pn` VALUES LESS THAN MAXVALUE ENGINE = MyISAM) +SELECT * FROM t1; +x +12 +2 +22 +32 +42 +52 +DROP TABLE t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2; +DROP TABLE t2; +set session debug_dbug=@save_dbug; +# +# MDEV-22166 CONVERT PARTITION: move out partition into a table # set @save_dbug=@@debug_dbug; set session debug_dbug="+d,fail_create_before_create_frm"; diff --git a/mysql-test/suite/parts/r/partition_debug_innodb.result b/mysql-test/suite/parts/r/partition_debug_innodb.result index 15d670ff416..db88e714872 100644 --- a/mysql-test/suite/parts/r/partition_debug_innodb.result +++ b/mysql-test/suite/parts/r/partition_debug_innodb.result @@ -961,25 +961,13 @@ SET @save_dbug=@@debug_dbug; SET SESSION debug_dbug="+d,exchange_partition_fail_1"; CREATE TABLE t2 (a INT, b VARCHAR(64)) ENGINE = InnoDB; 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=InnoDB 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)) ENGINE = InnoDB 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 +# d,exchange_partition_fail_1: BEFORE failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1010,9 +998,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(64) DEFAULT NULL +) ENGINE=InnoDB 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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_1: AFTER failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1061,25 +1061,13 @@ SET SESSION debug_dbug=@save_dbug; SET SESSION debug_dbug="+d,exchange_partition_fail_2"; CREATE TABLE t2 (a INT, b VARCHAR(64)) ENGINE = InnoDB; 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=InnoDB 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)) ENGINE = InnoDB 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 +# d,exchange_partition_fail_2: BEFORE failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1110,9 +1098,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(64) DEFAULT NULL +) ENGINE=InnoDB 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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_2: AFTER failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1161,25 +1161,13 @@ SET SESSION debug_dbug=@save_dbug; SET SESSION debug_dbug="+d,exchange_partition_fail_3"; CREATE TABLE t2 (a INT, b VARCHAR(64)) ENGINE = InnoDB; 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=InnoDB 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)) ENGINE = InnoDB 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 +# d,exchange_partition_fail_3: BEFORE failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1210,9 +1198,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(64) DEFAULT NULL +) ENGINE=InnoDB 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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error on rename of './test/t2' to './test/#sql-exchange' (errno: 0 "Internal error/check (Not system error)") -# State after failure +# d,exchange_partition_fail_3: AFTER failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1261,25 +1261,13 @@ SET SESSION debug_dbug=@save_dbug; SET SESSION debug_dbug="+d,exchange_partition_fail_4"; CREATE TABLE t2 (a INT, b VARCHAR(64)) ENGINE = InnoDB; 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=InnoDB 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)) ENGINE = InnoDB 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 +# d,exchange_partition_fail_4: BEFORE failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1310,9 +1298,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(64) DEFAULT NULL +) ENGINE=InnoDB 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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_4: AFTER failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1361,25 +1361,13 @@ SET SESSION debug_dbug=@save_dbug; SET SESSION debug_dbug="+d,exchange_partition_fail_5"; CREATE TABLE t2 (a INT, b VARCHAR(64)) ENGINE = InnoDB; 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=InnoDB 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)) ENGINE = InnoDB 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 +# d,exchange_partition_fail_5: BEFORE failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1410,9 +1398,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(64) DEFAULT NULL +) ENGINE=InnoDB 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 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 +# d,exchange_partition_fail_5: AFTER failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1461,25 +1461,13 @@ SET SESSION debug_dbug=@save_dbug; SET SESSION debug_dbug="+d,exchange_partition_fail_6"; CREATE TABLE t2 (a INT, b VARCHAR(64)) ENGINE = InnoDB; 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=InnoDB 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)) ENGINE = InnoDB 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 +# d,exchange_partition_fail_6: BEFORE failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1510,9 +1498,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(64) DEFAULT NULL +) ENGINE=InnoDB 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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_6: AFTER failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1561,25 +1561,13 @@ SET SESSION debug_dbug=@save_dbug; SET SESSION debug_dbug="+d,exchange_partition_fail_7"; CREATE TABLE t2 (a INT, b VARCHAR(64)) ENGINE = InnoDB; 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=InnoDB 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)) ENGINE = InnoDB 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 +# d,exchange_partition_fail_7: BEFORE failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1610,9 +1598,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(64) DEFAULT NULL +) ENGINE=InnoDB 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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error on rename of './test/#sql-exchange' to './test/t1#P#p0' (errno: 0 "Internal error/check (Not system error)") -# State after failure +# d,exchange_partition_fail_7: AFTER failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1661,25 +1661,13 @@ SET SESSION debug_dbug=@save_dbug; SET SESSION debug_dbug="+d,exchange_partition_fail_8"; CREATE TABLE t2 (a INT, b VARCHAR(64)) ENGINE = InnoDB; 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=InnoDB 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)) ENGINE = InnoDB 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 +# d,exchange_partition_fail_8: BEFORE failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1710,9 +1698,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(64) DEFAULT NULL +) ENGINE=InnoDB 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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_8: AFTER failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1761,25 +1761,13 @@ SET SESSION debug_dbug=@save_dbug; SET SESSION debug_dbug="+d,exchange_partition_fail_9"; CREATE TABLE t2 (a INT, b VARCHAR(64)) ENGINE = InnoDB; 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=InnoDB 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)) ENGINE = InnoDB 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 +# d,exchange_partition_fail_9: BEFORE failure db.opt t1#P#p0.ibd t1#P#p1.ibd @@ -1810,9 +1798,21 @@ a b 24 Original from partition p1 3 Original from partition p0 4 Original from partition p0 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(64) DEFAULT NULL +) ENGINE=InnoDB 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 ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2; ERROR HY000: Error in DDL log -# State after failure +# d,exchange_partition_fail_9: AFTER failure db.opt t1#P#p0.ibd t1#P#p1.ibd diff --git a/mysql-test/suite/parts/t/alter_table.test b/mysql-test/suite/parts/t/alter_table.test index 0d605c11bd6..741a9450c8e 100644 --- a/mysql-test/suite/parts/t/alter_table.test +++ b/mysql-test/suite/parts/t/alter_table.test @@ -39,7 +39,72 @@ DROP VIEW v1; DROP TABLE t1, t2; --echo # ---echo # MDEV-22166 MIGRATE PARTITION: move out partition into a table +--echo # MDEV-22165 CONVERT PARTITION: move in partition from existing table +--echo # +create or replace table tp1 (a int); +create or replace table t1 (a int) +partition by hash (a) partitions 2; +--error ER_ONLY_ON_RANGE_LIST_PARTITION +alter table t1 convert table tp1 to partition p2; + +create or replace table t1 (a int) +partition by range (a) +(partition p0 values less than (0)); + +--error ER_NO_SUCH_TABLE +alter table t1 convert table non_existent to partition p1 values less than (10); +alter table t1 convert table tp1 to partition p1 values less than (10); +--error ER_NO_SUCH_TABLE +show create table tp1; +--replace_result $engine X ' PAGE_CHECKSUM=1' '' +show create table t1; + +create table tp2 (x int); +--error ER_TABLES_DIFFERENT_METADATA +alter table t1 convert table tp2 to partition p2 values less than (20); +--replace_result $engine X ' PAGE_CHECKSUM=1' '' +show create table tp2; +--replace_result $engine X ' PAGE_CHECKSUM=1' '' +show create table t1; + +create or replace table tp2 (a int); +insert tp2 values (1), (15), (17); +--error ER_ROW_DOES_NOT_MATCH_PARTITION +alter table t1 convert table tp2 to partition p2 values less than (20); +delete from tp2; +insert tp2 values (15), (1), (17); +--error ER_ROW_DOES_NOT_MATCH_PARTITION +alter table t1 convert table tp2 to partition p2 values less than (20); +delete from tp2; +insert tp2 values (15), (17), (1); +--error ER_ROW_DOES_NOT_MATCH_PARTITION +alter table t1 convert table tp2 to partition p2 values less than (20); +delete from tp2; +insert tp2 values (15), (17); +alter table t1 convert table tp2 to partition p2 values less than (20); +--error ER_NO_SUCH_TABLE +show create table tp2; +--replace_result $engine X ' PAGE_CHECKSUM=1' '' +show create table t1; +select * from t1 partition (p2); + +create or replace table t1 (a int) +partition by range (a) ( +p0 values less than (0), +pn values less than (30)); +insert into t1 values (1); +create or replace table tp1 (a int); +insert into tp1 values (2); +# TODO: would be good to automatically detect order of partitions, +# as well as move the data from succeeding partitions (ADD PARTITION FR). +--error ER_RANGE_NOT_INCREASING_ERROR +alter table t1 convert table tp1 to partition p1 values less than (10); + +drop tables t1, tp1; + + +--echo # +--echo # MDEV-22166 CONVERT PARTITION: move out partition into a table --echo # create or replace table t1 (x int); diff --git a/mysql-test/suite/parts/t/partition_debug.test b/mysql-test/suite/parts/t/partition_debug.test index 48b3392aa4f..74728074c24 100644 --- a/mysql-test/suite/parts/t/partition_debug.test +++ b/mysql-test/suite/parts/t/partition_debug.test @@ -52,7 +52,52 @@ let $fail_statement= $crash_statement; --source suite/parts/inc/partition_fail_exchange.inc --echo # ---echo # MDEV-22166 MIGRATE PARTITION: move out partition into a table +--echo # MDEV-22165 CONVERT PARTITION: move in partition from existing table +--echo # +let $create_statement= create or replace table t1 (x int primary key) + partition by range(x) ( + partition p1 values less than (10), + partition p2 values less than (20), + partition p3 values less than (30)); + +let $create_statement2= create or replace table t2 (x int primary key); +let $insert_statement= insert into t1 values (2), (12), (22); +let $insert_statement2= insert into t2 values (32), (42), (52); + +let $fail_statement= alter table t1 convert table t2 to partition pn values less than maxvalue; + +set @save_dbug=@@debug_dbug; +set session debug_dbug="+d,fail_convert_partition_1"; +--source suite/parts/inc/partition_fail_t2.inc +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_2"; +--source suite/parts/inc/partition_fail_t2.inc +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_3"; +--source suite/parts/inc/partition_fail_t2.inc +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_4"; +--source suite/parts/inc/partition_fail_t2.inc +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_5"; +--source suite/parts/inc/partition_fail_t2.inc +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_6"; +--source suite/parts/inc/partition_fail_t2.inc +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_7"; +--source suite/parts/inc/partition_fail_t2.inc +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_8"; +--source suite/parts/inc/partition_fail_t2.inc +set session debug_dbug=@save_dbug; +set session debug_dbug="+d,fail_convert_partition_9"; +--source suite/parts/inc/partition_fail_t2.inc +set session debug_dbug=@save_dbug; + + +--echo # +--echo # MDEV-22166 CONVERT PARTITION: move out partition into a table --echo # let $create_statement= create or replace table t1 (x int primary key) partition by range(x) ( diff --git a/sql/handler.h b/sql/handler.h index 657618ab4e7..d2b6674f773 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -823,9 +823,9 @@ typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*); // Set by Sql_cmd_alter_table_truncate_partition::execute() #define ALTER_PARTITION_TRUNCATE (1ULL << 11) // Set for REORGANIZE PARTITION -#define ALTER_PARTITION_TABLE_REORG (1ULL << 12) -#define ALTER_PARTITION_CONVERT_OUT (1ULL << 13) -#define ALTER_PARTITION_ADD_FROM_TABLE (1ULL << 14) +#define ALTER_PARTITION_TABLE_REORG (1ULL << 12) +#define ALTER_PARTITION_CONVERT_IN (1ULL << 13) +#define ALTER_PARTITION_CONVERT_OUT (1ULL << 14) /* This is master database for most of system tables. However there diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index bba9357122d..904c80d9f55 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7992,5 +7992,3 @@ ER_STORAGE_ENGINE_DISABLED eng "Storage engine %s is disabled" ER_PARTITION_CONVERT_SUBPARTITIONED eng "Convert partition is not supported for subpartitioned table." -ER_PARTITION_METHOD_NOT_COMPATIBLE_WITH_ADD_FROM_TABLE - eng "ADD PARTITION FROM TABLE is not compatible with %s table partition method" diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc index 889eca2f4ba..747449f9718 100644 --- a/sql/sql_alter.cc +++ b/sql/sql_alter.cc @@ -440,8 +440,8 @@ bool Sql_cmd_alter_table::execute(THD *thd) as for RENAME TO, as being done by SQLCOM_RENAME_TABLE */ if ((alter_info.partition_flags & ALTER_PARTITION_DROP) || + (alter_info.partition_flags & ALTER_PARTITION_CONVERT_IN) || (alter_info.partition_flags & ALTER_PARTITION_CONVERT_OUT) || - (alter_info.partition_flags & ALTER_PARTITION_ADD_FROM_TABLE) || (alter_info.flags & ALTER_RENAME)) priv_needed|= DROP_ACL; diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 67f12543c3a..5efb9786092 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -6045,8 +6045,10 @@ int st_select_lex_unit::save_union_explain_part2(Explain_query *output) bool LEX::is_partition_management() const { return (sql_command == SQLCOM_ALTER_TABLE && - (alter_info.partition_flags == ALTER_PARTITION_ADD || - alter_info.partition_flags == ALTER_PARTITION_REORGANIZE)); + (alter_info.partition_flags & (ALTER_PARTITION_ADD | + ALTER_PARTITION_CONVERT_IN | + ALTER_PARTITION_CONVERT_OUT | + ALTER_PARTITION_REORGANIZE))); } diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 14db4054642..dd00b8900b0 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -4876,7 +4876,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, ALTER_PARTITION_REORGANIZE | ALTER_PARTITION_TABLE_REORG | ALTER_PARTITION_REBUILD | - ALTER_PARTITION_ADD_FROM_TABLE)) + ALTER_PARTITION_CONVERT_IN)) { /* You can't add column when we are doing alter related to partition @@ -5080,9 +5080,15 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info, goto err; } } - if ((alter_info->partition_flags & ALTER_PARTITION_ADD) || - (alter_info->partition_flags & ALTER_PARTITION_ADD_FROM_TABLE)) + if ((alter_info->partition_flags & ALTER_PARTITION_ADD)) { + if ((alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN) && + !(tab_part_info->part_type == RANGE_PARTITION || + tab_part_info->part_type == LIST_PARTITION)) + { + my_error(ER_ONLY_ON_RANGE_LIST_PARTITION, MYF(0), "CONVERT TABLE TO"); + goto err; + } if (*fast_alter_table && thd->locked_tables_mode) { MEM_ROOT *old_root= thd->mem_root; @@ -6435,14 +6441,22 @@ static bool write_log_changed_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, FALSE Success */ +enum log_action_enum +{ + ACT_DROP = 0, + ACT_CONVERT_IN, + ACT_CONVERT_OUT +}; + static bool log_drop_or_convert_action(ALTER_PARTITION_PARAM_TYPE *lpt, uint *next_entry, const char *path, const char *from_name, - bool temp_list) + bool temp_list, + const log_action_enum convert_action) { DDL_LOG_ENTRY ddl_log_entry; - const bool convert_action= (from_name != NULL); + DBUG_ASSERT(convert_action == ACT_DROP || (from_name != NULL)); partition_info *part_info= lpt->part_info; DDL_LOG_MEMORY_ENTRY *log_entry; char tmp_path[FN_REFLEN + 1]; @@ -6477,7 +6491,10 @@ static bool log_drop_or_convert_action(ALTER_PARTITION_PARAM_TYPE *lpt, name_variant= TEMP_PART_NAME; else name_variant= NORMAL_PART_NAME; - DBUG_ASSERT(!convert_action || part_elem->part_state == PART_TO_BE_DROPPED); + DBUG_ASSERT(convert_action != ACT_CONVERT_IN || + part_elem->part_state == PART_TO_BE_ADDED); + DBUG_ASSERT(convert_action != ACT_CONVERT_OUT || + part_elem->part_state == PART_TO_BE_DROPPED); if (part_info->is_sub_partitioned()) { DBUG_ASSERT(!convert_action); @@ -6514,9 +6531,18 @@ static bool log_drop_or_convert_action(ALTER_PARTITION_PARAM_TYPE *lpt, part_elem->partition_name, name_variant, TRUE)) DBUG_RETURN(TRUE); - ddl_log_entry.name= { tmp_path, strlen(tmp_path) }; - if (convert_action) - ddl_log_entry.from_name= { from_name, strlen(from_name) }; + switch (convert_action) + { + case ACT_CONVERT_OUT: + ddl_log_entry.from_name= { from_name, strlen(from_name) }; + /* fall through */ + case ACT_DROP: + ddl_log_entry.name= { tmp_path, strlen(tmp_path) }; + break; + case ACT_CONVERT_IN: + ddl_log_entry.name= { from_name, strlen(from_name) }; + ddl_log_entry.from_name= { tmp_path, strlen(tmp_path) }; + } if (ddl_log_write_entry(&ddl_log_entry, &log_entry)) { DBUG_RETURN(TRUE); @@ -6537,19 +6563,24 @@ static bool write_log_dropped_partitions(ALTER_PARTITION_PARAM_TYPE *lpt, const char *path, bool temp_list) { - return log_drop_or_convert_action(lpt, next_entry, path, NULL, temp_list); + return log_drop_or_convert_action(lpt, next_entry, path, NULL, temp_list, ACT_DROP); } inline -static bool write_log_convert_out_partition(ALTER_PARTITION_PARAM_TYPE *lpt, - uint *next_entry, - const char *path) -{ - char from_name[FN_REFLEN + 1]; - build_table_filename(from_name, sizeof(from_name) - 1, lpt->alter_ctx->new_db.str, +static bool write_log_convert_partition(ALTER_PARTITION_PARAM_TYPE *lpt, + uint *next_entry, + const char *path) +{ + char other_table[FN_REFLEN + 1]; + const auto f= lpt->alter_info->partition_flags; + DBUG_ASSERT((f & ALTER_PARTITION_CONVERT_IN) || (f & ALTER_PARTITION_CONVERT_OUT)); + const log_action_enum convert_action= (f & ALTER_PARTITION_CONVERT_IN) ? + ACT_CONVERT_IN : ACT_CONVERT_OUT; + build_table_filename(other_table, sizeof(other_table) - 1, lpt->alter_ctx->new_db.str, lpt->alter_ctx->new_name.str, "", 0); DDL_LOG_MEMORY_ENTRY *main_entry= lpt->part_info->main_entry; - bool res= log_drop_or_convert_action(lpt, next_entry, path, from_name, false); + bool res= log_drop_or_convert_action(lpt, next_entry, path, other_table, + false, convert_action); /* NOTE: main_entry is "drop shadow frm", we have to keep it like this, because partitioning crash-safety disables it at install shadow FRM phase @@ -6594,6 +6625,16 @@ static bool write_log_drop_shadow_frm(ALTER_PARTITION_PARAM_TYPE *lpt, if (write_log_delete_frm(lpt, (const char*)path)) goto error; + if (flags & WFRM_DROP_CONVERTED_FROM) + { + TABLE_LIST *table_from= lpt->table_list->next_local; + build_table_filename(path, sizeof(path) - 1, table_from->db.str, + table_from->table_name.str, "", 0); + + if (write_log_delete_frm(lpt, (const char*) path)) + goto error; + } + log_entry= part_info->list; if (ddl_log_write_execute_entry(log_entry->entry_pos, &part_info->execute_entry)) @@ -6713,7 +6754,7 @@ error: } -static bool write_log_convert_out_partition(ALTER_PARTITION_PARAM_TYPE *lpt) +static bool write_log_convert_partition(ALTER_PARTITION_PARAM_TYPE *lpt) { partition_info *part_info= lpt->part_info; char tmp_path[FN_REFLEN + 1]; @@ -6725,7 +6766,7 @@ static bool write_log_convert_out_partition(ALTER_PARTITION_PARAM_TYPE *lpt) mysql_mutex_lock(&LOCK_gdl); - if (write_log_convert_out_partition(lpt, &next_entry, (const char*)path)) + if (write_log_convert_partition(lpt, &next_entry, (const char*)path)) goto error; DBUG_ASSERT(next_entry == part_info->list->entry_pos); if (ddl_log_write_execute_entry(part_info->list->entry_pos, @@ -7207,16 +7248,11 @@ bool log_partition_alter_to_ddl_log(ALTER_PARTITION_PARAM_TYPE *lpt) } -extern bool move_table_to_partition(ALTER_PARTITION_PARAM_TYPE *lpt); - +extern bool alter_partition_convert_in(ALTER_PARTITION_PARAM_TYPE *lpt); /** - Check that definition of a table specified in the clause FROM of - the statement ALTER TABLE <tablename> ADD PARTITION ... FROM <from_table> - fit with definition of a partition being added and every row stored in - the table <from_table> conform with partition's expression. On return from - the function an actual name of a file corresponding to the partition - is stored in the buffer part_file_name_buf. + Check that definition of source table fits definition of partition being + added and every row stored in the table conforms partition's expression. @param lpt Structure containing parameters required for checking @param[in,out] part_file_name_buf Buffer for storing a partition name @@ -7227,8 +7263,12 @@ extern bool move_table_to_partition(ALTER_PARTITION_PARAM_TYPE *lpt); @return false on success, true on error */ -static bool check_table_data_fit_new_partition(ALTER_PARTITION_PARAM_TYPE *lpt) +static bool check_table_data(ALTER_PARTITION_PARAM_TYPE *lpt) { + /* + TODO: if destination is partitioned by range(X) and source is indexed by X + then just get min(X) and max(X) from index. + */ THD *thd= lpt->thd; TABLE *table_to= lpt->table_list->table; TABLE *table_from= lpt->table_list->next_local->table; @@ -7245,10 +7285,7 @@ static bool check_table_data_fit_new_partition(ALTER_PARTITION_PARAM_TYPE *lpt) uint32 new_part_id; partition_element *part_elem; - // FIXME: really? - const char* partition_name= - thd->lex->part_info->curr_part_elem->partition_name; - + const char* partition_name= thd->lex->part_info->curr_part_elem->partition_name; part_elem= table_to->part_info->get_part_elem(partition_name, nullptr, 0, &new_part_id); if (unlikely(!part_elem)) @@ -7271,114 +7308,6 @@ static bool check_table_data_fit_new_partition(ALTER_PARTITION_PARAM_TYPE *lpt) /** - Check whether metadata of a partitioned table and a being moved to partition - are equal - - @para[in, out] lpt Struct containing parameters required for handling of - the statement ALTER TABLE - - @return false on ok (tables metadata are equal), - true on error (tables metadata are different) -*/ - -static bool compare_tables_metadata(ALTER_PARTITION_PARAM_TYPE *lpt) -{ - TABLE *part_table= lpt->table_list->table; - TABLE *table= lpt->table_list->next_local->table; - bool metadata_equal; - HA_CREATE_INFO *part_create_info= lpt->create_info; - - handlerton *db_type= part_create_info->db_type; - part_create_info->db_type= part_table->part_info->default_engine_type; - - if (mysql_compare_tables(table, lpt->alter_info, part_create_info, - &metadata_equal)) - - { - part_create_info->db_type= db_type; - my_error(ER_TABLES_DIFFERENT_METADATA, MYF(0)); - return true; - } - - part_create_info->db_type= db_type; - - DEBUG_SYNC(lpt->thd, "swap_partition_after_compare_tables"); - if (!metadata_equal) - { - my_error(ER_TABLES_DIFFERENT_METADATA, MYF(0)); - return true; - } - DBUG_ASSERT(table->s->db_create_options == - part_table->s->db_create_options); - DBUG_ASSERT(table->s->db_options_in_use == - part_table->s->db_options_in_use); - - if (table->s->avg_row_length != part_create_info->avg_row_length) - { - my_error(ER_PARTITION_EXCHANGE_DIFFERENT_OPTION, MYF(0), - "AVG_ROW_LENGTH"); - return true; - } - - if (table->s->db_create_options != part_create_info->table_options) - { - my_error(ER_PARTITION_EXCHANGE_DIFFERENT_OPTION, MYF(0), - "TABLE OPTION"); - return true; - } - - if (table->s->table_charset != part_table->s->table_charset) - { - my_error(ER_PARTITION_EXCHANGE_DIFFERENT_OPTION, MYF(0), - "CHARACTER SET"); - return true; - } - - return false; -} - - -/** - For the statement is ALTER TABLE ... ADD PARTITION... FROM <tbl_name> - check that partition metadata is compatible with table definition and - partition type supported for moving table to partition. - - @param lpt Structure containing parameters required for handling of - the statement ALTER TABLE - - @return false on success, true on failure -*/ - -static bool check_table_and_partition_compatibility( - ALTER_PARTITION_PARAM_TYPE *lpt) -{ - partition_info* tab_part_info= lpt->table->part_info; - DBUG_ASSERT((lpt->alter_info->partition_flags & - ALTER_PARTITION_ADD_FROM_TABLE)); - if (tab_part_info->part_type != RANGE_PARTITION && - tab_part_info->part_type != LIST_PARTITION) - { - /* - ALTER TABLE ... ADD PARTITION ... FROM TABLE is not compatible with - partition methods other RANGE and LIST. - */ - my_error(ER_PARTITION_METHOD_NOT_COMPATIBLE_WITH_ADD_FROM_TABLE, - MYF(0), (tab_part_info->part_type == HASH_PARTITION ? - "HASH": "VERSIONING")); - return true; - } - - if (compare_tables_metadata(lpt)) - return true; - - if (check_table_data_fit_new_partition(lpt)) - return true; - - return false; -} - - -/** Actually perform the change requested by ALTER TABLE of partitions previously prepared. @@ -7615,7 +7544,7 @@ uint fast_alter_partition_table(THD *thd, TABLE *table, wait_while_table_is_used(thd, table, HA_EXTRA_NOT_USED) || ERROR_INJECT_CRASH("crash_convert_partition_4") || ERROR_INJECT_ERROR("fail_convert_partition_4") || - write_log_convert_out_partition(lpt) || + write_log_convert_partition(lpt) || ERROR_INJECT_CRASH("crash_convert_partition_5") || ERROR_INJECT_ERROR("fail_convert_partition_5") || alter_close_table(lpt) || @@ -7663,55 +7592,60 @@ uint fast_alter_partition_table(THD *thd, TABLE *table, if (alter_partition_lock_handling(lpt)) goto err; } - else if ((alter_info->partition_flags & ALTER_PARTITION_ADD_FROM_TABLE)) + else if ((alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN)) { TABLE *table_from= table_list->next_local->table; + if (wait_while_table_is_used(thd, table, HA_EXTRA_NOT_USED) || + wait_while_table_is_used(thd, table_from, HA_EXTRA_PREPARE_FOR_RENAME) || + ERROR_INJECT_CRASH("crash_convert_partition_1") || + ERROR_INJECT_ERROR("fail_convert_partition_1") || + compare_table_with_partition(thd, table_from, table, NULL, 0) || + ERROR_INJECT_CRASH("crash_convert_partition_2") || + ERROR_INJECT_ERROR("fail_convert_partition_2") || + check_table_data(lpt)) + goto err; + if (write_log_drop_shadow_frm(lpt) || - ERROR_INJECT_CRASH("crash_add_partition_from_1") || - ERROR_INJECT_ERROR("fail_add_partition_from_1") || + ERROR_INJECT_CRASH("crash_convert_partition_3") || + ERROR_INJECT_ERROR("fail_convert_partition_3") || mysql_write_frm(lpt, WFRM_WRITE_SHADOW) || - ERROR_INJECT_CRASH("crash_add_partition_from_2") || - ERROR_INJECT_ERROR("fail_add_partition_from_2") || - wait_while_table_is_used(thd, table, HA_EXTRA_NOT_USED) || - wait_while_table_is_used(thd, table_from, - HA_EXTRA_PREPARE_FOR_RENAME) || - - ERROR_INJECT_CRASH("crash_add_partition_from_3") || - ERROR_INJECT_ERROR("fail_add_partition_from_3") || - write_log_add_change_partition(lpt) || - ERROR_INJECT_CRASH("crash_add_partition_from_4") || - ERROR_INJECT_ERROR("fail_add_partition_from_4") || - mysql_change_partitions(lpt) || - ERROR_INJECT_CRASH("crash_add_partition_from_5") || - ERROR_INJECT_ERROR("fail_add_partition_from_5") || + ERROR_INJECT_CRASH("crash_convert_partition_4") || + ERROR_INJECT_ERROR("fail_convert_partition_4") || alter_close_table(lpt) || - ERROR_INJECT_CRASH("crash_add_partition_from_6") || - ERROR_INJECT_ERROR("fail_add_partition_from_6") || - check_table_and_partition_compatibility(lpt) || - move_table_to_partition(lpt) || - ERROR_INJECT_CRASH("crash_add_partition_from_7") || - ERROR_INJECT_ERROR("fail_add_partition_from_7") || - write_log_rename_frm(lpt) || - (action_completed= TRUE, FALSE) || - ERROR_INJECT_CRASH("crash_add_partition_from_8") || - ERROR_INJECT_ERROR("fail_add_partition_from_8") || - (frm_install= TRUE, FALSE) || - mysql_write_frm(lpt, WFRM_INSTALL_SHADOW) || + ERROR_INJECT_CRASH("crash_convert_partition_5") || + ERROR_INJECT_ERROR("fail_convert_partition_5") || + write_log_convert_partition(lpt) || + ERROR_INJECT_CRASH("crash_convert_partition_6") || + ERROR_INJECT_ERROR("fail_convert_partition_6") || + alter_partition_convert_in(lpt) || + ERROR_INJECT_CRASH("crash_convert_partition_7") || + ERROR_INJECT_ERROR("fail_convert_partition_7") || + (frm_install= true, false) || + mysql_write_frm(lpt, WFRM_INSTALL_SHADOW|WFRM_BACKUP_ORIGINAL) || log_partition_alter_to_ddl_log(lpt) || - (frm_install= FALSE, FALSE) || - ERROR_INJECT_CRASH("crash_add_partition_from_9") || - ERROR_INJECT_ERROR("fail_add_partition_from_9") || - (write_log_completed(lpt, FALSE), FALSE) || + (frm_install= false, false) || + ERROR_INJECT_CRASH("crash_convert_partition_8") || + ERROR_INJECT_ERROR("fail_convert_partition_8") || ((!thd->lex->no_write_to_binlog) && - (write_bin_log(thd, FALSE, - thd->query(), thd->query_length()), FALSE)) || - ERROR_INJECT_CRASH("crash_add_partition_from_10") || - ERROR_INJECT_ERROR("fail_add_partition_from_10")) + (thd->binlog_xid= thd->query_id, + ddl_log_update_xid(lpt->part_info, thd->binlog_xid), + write_bin_log(thd, false, + thd->query(), thd->query_length()), + thd->binlog_xid= 0)) || + (ddl_log_complete(lpt->part_info), false) || + /* See above TODO (ALTER_PARTITION_CONVERT_OUT). */ + write_log_drop_shadow_frm(lpt, WFRM_DROP_BACKUP | + WFRM_DROP_CONVERTED_FROM) || + ERROR_INJECT_CRASH("crash_convert_partition_9") || + ERROR_INJECT_ERROR("fail_extract_partition_9")) { + (void) ddl_log_revert(thd, lpt->part_info); handle_alter_part_error(lpt, action_completed, FALSE, frm_install); goto err; } + /* Drop backup frm and converted from frm */ + (void) ddl_log_revert(thd, lpt->part_info); if (alter_partition_lock_handling(lpt)) goto err; @@ -7720,7 +7654,7 @@ uint fast_alter_partition_table(THD *thd, TABLE *table, (part_info->part_type == RANGE_PARTITION || part_info->part_type == LIST_PARTITION)) { - DBUG_ASSERT(!(alter_info->partition_flags & ALTER_PARTITION_ADD_FROM_TABLE)); + DBUG_ASSERT(!(alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN)); /* ADD RANGE/LIST PARTITIONS In this case there are no tuples removed and no tuples are added. diff --git a/sql/sql_partition.h b/sql/sql_partition.h index 04db1036c9e..795b3dbcda9 100644 --- a/sql/sql_partition.h +++ b/sql/sql_partition.h @@ -279,6 +279,10 @@ bool verify_data_with_partition(TABLE *table, TABLE *part_table, uint32 part_id); bool compare_partition_options(HA_CREATE_INFO *table_create_info, partition_element *part_elem); +bool compare_table_with_partition(THD *thd, TABLE *table, + TABLE *part_table, + partition_element *part_elem, + uint part_id); bool partition_key_modified(TABLE *table, const MY_BITMAP *fields); bool write_log_replace_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint next_entry, diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc index b64386eae23..afa61c15644 100644 --- a/sql/sql_partition_admin.cc +++ b/sql/sql_partition_admin.cc @@ -194,10 +194,10 @@ static bool check_exchange_partition(TABLE *table, TABLE *part_table) @param part_table Partitioned table. @param part_elem Partition element to use for partition specific compare. */ -static bool compare_table_with_partition(THD *thd, TABLE *table, - TABLE *part_table, - partition_element *part_elem, - uint part_id) +bool compare_table_with_partition(THD *thd, TABLE *table, + TABLE *part_table, + partition_element *part_elem, + uint part_id) { HA_CREATE_INFO table_create_info, part_create_info; Alter_info part_alter_info; @@ -294,7 +294,7 @@ static bool compare_table_with_partition(THD *thd, TABLE *table, The workaround is to use REORGANIZE PARTITION to rewrite the frm file and then use EXCHANGE PARTITION when they are the same. */ - if (compare_partition_options(&table_create_info, part_elem)) + if (part_elem && compare_partition_options(&table_create_info, part_elem)) DBUG_RETURN(TRUE); DBUG_RETURN(FALSE); @@ -991,22 +991,6 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd) } -// FIXME: replace with ddl_log_complete() -static void finalize_ddl_log_entry(DDL_LOG_MEMORY_ENTRY *log_entry, - DDL_LOG_MEMORY_ENTRY **exec_log_entry) -{ - (void) ddl_log_execute_entry(current_thd, log_entry->entry_pos); - mysql_mutex_lock(&LOCK_gdl); - /* mark the execute log entry done */ - (void) ddl_log_disable_execute_entry(exec_log_entry); - /* release the execute log entry */ - ddl_log_release_memory_entry(*exec_log_entry); - /* release the action log entry */ - ddl_log_release_memory_entry(log_entry); - mysql_mutex_unlock(&LOCK_gdl); -} - - /** Move a table specified by the clause FROM <table_name> of the statement ALTER TABLE ... ADD PARTITION ... FROM <table_name> to the new partition. @@ -1018,16 +1002,12 @@ static void finalize_ddl_log_entry(DDL_LOG_MEMORY_ENTRY *log_entry, @return false on success, true on error */ -bool move_table_to_partition(ALTER_PARTITION_PARAM_TYPE *lpt) +bool alter_partition_convert_in(ALTER_PARTITION_PARAM_TYPE *lpt) { char part_file_name[2*FN_REFLEN+1]; THD *thd= lpt->thd; const char *path= lpt->table_list->table->s->path.str; TABLE_LIST *table_from= lpt->table_list->next_local; - LEX_CSTRING &path_from= table_from->table->s->path; - char frm_from[FN_REFLEN + 1]; - memcpy(frm_from, LEX_STRING_WITH_LEN(path_from)); - strmov(frm_from + path_from.length, reg_ext); const char *partition_name= thd->lex->part_info->curr_part_elem->partition_name; @@ -1045,109 +1025,13 @@ bool move_table_to_partition(ALTER_PARTITION_PARAM_TYPE *lpt) table_from->table_name.str, "", 0); - handler *file_ptr= - get_new_handler(nullptr, thd->mem_root, - table_from->table->file->ht); + handler *file_ptr= get_new_handler(nullptr, thd->mem_root, + table_from->table->file->ht); if (unlikely(!file_ptr)) return true; - /* - Install the guard object to delete a pointer to the class handler on return - from this function. - */ std::unique_ptr<handler> file(file_ptr); - DDL_LOG_ENTRY move_entry; - DDL_LOG_MEMORY_ENTRY *log_entry= nullptr; - DDL_LOG_MEMORY_ENTRY *exec_log_entry= nullptr; - - bzero(&move_entry, sizeof(move_entry)); - move_entry.action_type= DDL_LOG_RENAME_ACTION; - lex_string_set(&move_entry.name, part_file_name); - lex_string_set(&move_entry.from_name, from_file_name); - lex_string_set(&move_entry.handler_name, - ha_resolve_storage_engine_name( - table_from->table->file->ht)); - move_entry.phase= EXCH_PHASE_NAME_TO_TEMP; - - mysql_mutex_lock(&LOCK_gdl); - - /* - Install the guard object to release LOCK_gdl on any return from the current - function that could be happened before this lock explicitly released - */ - auto lock_gdl_unlocker = make_scope_exit( - []() { - mysql_mutex_unlock(&LOCK_gdl); - } - ); - DBUG_EXECUTE_IF("move_partition_fail_1", return true;); - DBUG_EXECUTE_IF("move_partition_abort_1", DBUG_SUICIDE();); - if (unlikely(ddl_log_write_entry(&move_entry, &log_entry))) - { - my_error(ER_DDL_LOG_ERROR, MYF(0)); - return true; - } - - DBUG_EXECUTE_IF("move_partition_fail_2", - ddl_log_release_memory_entry(log_entry); return true;); - DBUG_EXECUTE_IF("move_partition_abort_2", DBUG_SUICIDE();); - if (unlikely(ddl_log_write_execute_entry(log_entry->entry_pos, - &exec_log_entry))) - { - my_error(ER_DDL_LOG_ERROR, MYF(0)); - ddl_log_release_memory_entry(log_entry); - return true; - } - - mysql_mutex_unlock(&LOCK_gdl); - /* - Since the global mutex LOCK_gd has just been release, turn off - its guard object to avoid double releasing of the lock. - */ - lock_gdl_unlocker.release(); - - /* - Install the guard object to finalize ddl log entry on return from - the current function - */ - auto ddl_lock_finalizer = make_scope_exit( - [log_entry, &exec_log_entry]() - { - finalize_ddl_log_entry(log_entry, &exec_log_entry); - } - ); - - DBUG_EXECUTE_IF("move_partition_fail_3", - my_error(ER_ERROR_ON_RENAME, MYF(0), - from_file_name, part_file_name, 0); - return true;); - DBUG_EXECUTE_IF("move_partition_abort_3", DBUG_SUICIDE();); - - if (unlikely(file->delete_table(part_file_name))) - { - my_error(ER_ERROR_ON_RENAME, MYF(0), from_file_name, - part_file_name, my_errno); - return true; - } - - DBUG_EXECUTE_IF("move_partition_fail_4", - my_error(ER_DDL_LOG_ERROR, MYF(0)); - return true;); - DBUG_EXECUTE_IF("move_partition_abort_4", DBUG_SUICIDE();); - - if (unlikely(ddl_log_increment_phase(log_entry->entry_pos))) - { - my_error(ER_DDL_LOG_ERROR, MYF(0)); - return true; - } - - DBUG_EXECUTE_IF("move_partition_fail_5", - my_error(ER_ERROR_ON_RENAME, MYF(0), - from_file_name, part_file_name, 0); - return true;); - DBUG_EXECUTE_IF("move_partition_abort_5", DBUG_SUICIDE();); - close_all_tables_for_name(thd, table_from->table->s, HA_EXTRA_PREPARE_FOR_RENAME, nullptr); @@ -1158,28 +1042,6 @@ bool move_table_to_partition(ALTER_PARTITION_PARAM_TYPE *lpt) return true; } - DBUG_EXECUTE_IF("move_partition_fail_6", - my_error(ER_DDL_LOG_ERROR, MYF(0)); - return true;); - if (unlikely(ddl_log_increment_phase(log_entry->entry_pos))) - { - my_error(ER_DDL_LOG_ERROR, MYF(0)); - return true; - } - - if (mysql_file_delete(key_file_frm, frm_from, - MYF(MY_WME | MY_IGNORE_ENOENT))) - { - return true; - } - - /* The move is complete and ddl_log is deactivated */ - DBUG_EXECUTE_IF("exchange_partition_fail_9", - my_error(ER_DDL_LOG_ERROR, MYF(0)); - return true;); - DBUG_EXECUTE_IF("exchange_partition_abort_9", DBUG_SUICIDE();); - - /* all OK */ return false; } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index aff3fb13ff2..857e8f0d95d 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -880,7 +880,6 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) #else /* !WITH_PARTITION_STORAGE_ENGINE */ DBUG_ASSERT(!(flags & WFRM_WRITE_EXTRACTED)); DBUG_ASSERT(!(flags & WFRM_BACKUP_ORIGINAL)); - DBUG_ASSERT(!(flags & WFRM_DROP_BACKUP)); #endif /* !WITH_PARTITION_STORAGE_ENGINE */ if (flags & WFRM_INSTALL_SHADOW) { @@ -9694,7 +9693,8 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, Table maybe does not exist, but we got an exclusive lock on the name, now we can safely try to find out for sure. */ - if (ha_table_exists(thd, &alter_ctx.new_db, &alter_ctx.new_name)) + if (!(alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN) && + ha_table_exists(thd, &alter_ctx.new_db, &alter_ctx.new_name)) { /* Table will be closed in do_command() */ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias.str); diff --git a/sql/sql_table.h b/sql/sql_table.h index a580c7d348d..b80970afab9 100644 --- a/sql/sql_table.h +++ b/sql/sql_table.h @@ -67,6 +67,7 @@ enum enum_explain_filename_mode #define WFRM_WRITE_CONVERTED_TO 8 #define WFRM_BACKUP_ORIGINAL 16 #define WFRM_DROP_BACKUP 32 +#define WFRM_DROP_CONVERTED_FROM 64 /* Flags for conversion functions. */ static const uint FN_FROM_IS_TMP= 1 << 0; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index e4fda6a7ad6..d4a6a7519cc 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -7629,6 +7629,43 @@ alter_commands: MYSQL_YYABORT; lex->alter_info.partition_flags|= ALTER_PARTITION_CONVERT_OUT; } + | CONVERT_SYM TABLE_SYM table_ident + { + LEX *lex= Lex; + if (!lex->first_select_lex()->add_table_to_list(thd, $3, nullptr, 0, + TL_READ_NO_INSERT, + MDL_SHARED_NO_WRITE)) + MYSQL_YYABORT; + + /* + This will appear as (new_db, new_name) in alter_ctx. + new_db will be IX-locked and new_name X-locked. + */ + lex->first_select_lex()->db= $3->db; + lex->name= $3->table; + if (lex->first_select_lex()->db.str == NULL && + lex->copy_db_to(&lex->first_select_lex()->db)) + MYSQL_YYABORT; + + lex->part_info= new (thd->mem_root) partition_info(); + if (unlikely(!lex->part_info)) + MYSQL_YYABORT; + + lex->part_info->num_parts= 1; + /* + OR-ed with ALTER_PARTITION_ADD because too many checks of + ALTER_PARTITION_ADD required. + */ + lex->alter_info.partition_flags|= ALTER_PARTITION_ADD | + ALTER_PARTITION_CONVERT_IN; + } + TO_SYM PARTITION_SYM part_definition + { + LEX *lex= Lex; + lex->m_sql_cmd= new (thd->mem_root) Sql_cmd_alter_table(); + if (unlikely(lex->m_sql_cmd == NULL)) + MYSQL_YYABORT; + } ; remove_partitioning: |