Commit 69724805 authored by Aleksey Midenkov's avatar Aleksey Midenkov Committed by Sergei Golubchik

MDEV-22165 CONVERT TABLE: move in partition from existing table

Syntax for CONVERT TABLE

ALTER TABLE tbl_name 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.

Initial patch was done by Dmitry Shulga <dmitry.shulga@mariadb.com>
parent 7da721be
--- alter_partition.result
+++ alter_partition,innodb.reject
@@ -12,12 +12,9 @@
@@ -17,12 +17,9 @@
end $
# QUERY: ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1
# CRASH: crash_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: crash_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: crash_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,7 +195,7 @@
master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1
Table Create Table
t1 CREATE TABLE `t1` (
@@ -270,15 +234,12 @@
@@ -275,15 +239,12 @@
x
12
# CRASH: crash_convert_partition_10
......@@ -214,7 +214,7 @@
master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1
Table Create Table
t1 CREATE TABLE `t1` (
@@ -297,15 +258,12 @@
@@ -302,15 +263,12 @@
x
12
# CRASH: crash_convert_partition_11
......@@ -233,3 +233,293 @@
master-bin.000001 # Query # # use `test`; ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1
Table Create Table
t1 CREATE TABLE `t1` (
@@ -330,14 +288,10 @@
12
# QUERY: ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40)
# NO CRASH: crash_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)
@@ -357,14 +311,10 @@
32
39
# NO CRASH: crash_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)
@@ -384,14 +334,10 @@
32
39
# NO CRASH: crash_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)
@@ -411,17 +357,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
@@ -442,17 +384,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
@@ -473,17 +411,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
@@ -504,17 +438,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
@@ -535,17 +465,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
@@ -566,17 +492,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
@@ -597,17 +519,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
@@ -628,17 +546,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
@@ -659,14 +573,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)
@@ -686,14 +596,10 @@
32
39
# CRASH: crash_convert_partition_10
-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)
@@ -713,14 +619,10 @@
32
39
# CRASH: crash_convert_partition_11
-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)
# 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
......@@ -286,7 +291,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
......@@ -313,7 +318,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
......@@ -323,5 +328,416 @@ 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: crash_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: crash_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: crash_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
# CRASH: crash_convert_partition_10
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_11
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'
......@@ -55,22 +55,30 @@ let $crash_points='crash_create_before_create_frm',
#let $crash_count= 1;
#let $crash_points= 'crash_convert_partition_10';
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 ;
......@@ -95,7 +103,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;
......@@ -147,6 +155,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;
......
......@@ -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;
......@@ -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;
......
......@@ -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,925 @@ 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;
ERROR HY000: Unknown error
# 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.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_11";
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_11: 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_11: 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";
......
......@@ -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
......
......@@ -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);
......
......@@ -52,7 +52,55 @@ 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;
set session debug_dbug="+d,fail_convert_partition_11";
--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) (
......
......@@ -823,8 +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_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
......
......@@ -440,6 +440,7 @@ 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.flags & ALTER_RENAME))
priv_needed|= DROP_ACL;
......
......@@ -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)));
}
......
......@@ -4870,7 +4870,8 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
ALTER_PARTITION_COALESCE |
ALTER_PARTITION_REORGANIZE |
ALTER_PARTITION_TABLE_REORG |
ALTER_PARTITION_REBUILD))
ALTER_PARTITION_REBUILD |
ALTER_PARTITION_CONVERT_IN))
{
/*
You can't add column when we are doing alter related to partition
......@@ -5076,6 +5077,13 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
}
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;
......@@ -6387,12 +6395,20 @@ 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)
const char *from_name, 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];
......@@ -6427,7 +6443,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);
......@@ -6464,9 +6483,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);
......@@ -6486,18 +6514,24 @@ static bool write_log_dropped_partitions(ALTER_PARTITION_PARAM_TYPE *lpt,
uint *next_entry, 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 ulong 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.
......@@ -6537,6 +6571,16 @@ static bool write_log_drop_frm(ALTER_PARTITION_PARAM_TYPE *lpt,
if (ddl_log_delete_frm(drop_chain, (const char*)path))
goto error;
if (drop_backup && (lpt->alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN))
{
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 (ddl_log_delete_frm(drop_chain, (const char*) path))
goto error;
}
if (ddl_log_write_execute_entry(drop_chain->list->entry_pos,
drop_backup ?
main_chain->execute_entry->entry_pos : 0,
......@@ -6664,7 +6708,7 @@ static bool write_log_drop_partition(ALTER_PARTITION_PARAM_TYPE *lpt)
}
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];
......@@ -6676,7 +6720,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,
......@@ -7162,6 +7206,64 @@ bool log_partition_alter_to_ddl_log(ALTER_PARTITION_PARAM_TYPE *lpt)
}
extern bool alter_partition_convert_in(ALTER_PARTITION_PARAM_TYPE *lpt);
/**
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
@param part_file_name_buf_sz Size of buffer for storing a partition name
@param part_file_name_len Length of partition prefix stored in the buffer
on invocation of function
@return false on success, true on error
*/
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;
DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE,
table_to->s->db.str,
table_to->s->table_name.str,
MDL_EXCLUSIVE));
DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE,
table_from->s->db.str,
table_from->s->table_name.str,
MDL_EXCLUSIVE));
uint32 new_part_id;
partition_element *part_elem;
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))
return true;
if (unlikely(new_part_id == NOT_A_PARTITION_ID))
{
DBUG_ASSERT(table_to->part_info->is_sub_partitioned());
my_error(ER_PARTITION_INSTEAD_OF_SUBPARTITION, MYF(0));
return true;
}
if (verify_data_with_partition(table_from, table_to, new_part_id))
{
return true;
}
return false;
}
/**
Actually perform the change requested by ALTER TABLE of partitions
......@@ -7390,7 +7492,7 @@ uint fast_alter_partition_table(THD *thd, TABLE *table,
ERROR_INJECT("convert_partition_3") ||
wait_while_table_is_used(thd, table, HA_EXTRA_NOT_USED) ||
ERROR_INJECT("convert_partition_4") ||
write_log_convert_out_partition(lpt) ||
write_log_convert_partition(lpt) ||
ERROR_INJECT("convert_partition_5") ||
alter_close_table(lpt) ||
ERROR_INJECT("convert_partition_6") ||
......@@ -7419,10 +7521,60 @@ uint fast_alter_partition_table(THD *thd, TABLE *table,
ERROR_INJECT("convert_partition_11"))
goto err;
}
else if ((alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN))
{
DDL_LOG_STATE chain_drop_backup;
bzero(&chain_drop_backup, sizeof(chain_drop_backup));
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("convert_partition_1") ||
compare_table_with_partition(thd, table_from, table, NULL, 0) ||
ERROR_INJECT("convert_partition_2") ||
check_table_data(lpt))
goto err;
if (write_log_drop_shadow_frm(lpt) ||
ERROR_INJECT("convert_partition_3") ||
mysql_write_frm(lpt, WFRM_WRITE_SHADOW) ||
ERROR_INJECT("convert_partition_4") ||
alter_close_table(lpt) ||
ERROR_INJECT("convert_partition_5") ||
write_log_convert_partition(lpt) ||
ERROR_INJECT("convert_partition_6") ||
alter_partition_convert_in(lpt) ||
ERROR_INJECT("convert_partition_7") ||
(frm_install= true, false) ||
write_log_drop_frm(lpt, &chain_drop_backup) ||
mysql_write_frm(lpt, WFRM_INSTALL_SHADOW|WFRM_BACKUP_ORIGINAL) ||
log_partition_alter_to_ddl_log(lpt) ||
(frm_install= false, false) ||
ERROR_INJECT("convert_partition_8") ||
((!thd->lex->no_write_to_binlog) &&
((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))) ||
ERROR_INJECT("convert_partition_9"))
{
ddl_log_complete(&chain_drop_backup);
(void) ddl_log_revert(thd, lpt->part_info);
handle_alter_part_error(lpt, true, true, false);
goto err;
}
ddl_log_complete(lpt->part_info);
ERROR_INJECT("convert_partition_10");
(void) ddl_log_revert(thd, &chain_drop_backup);
if (alter_partition_lock_handling(lpt) ||
ERROR_INJECT("convert_partition_11"))
goto err;
}
else if ((alter_info->partition_flags & ALTER_PARTITION_ADD) &&
(part_info->part_type == RANGE_PARTITION ||
part_info->part_type == LIST_PARTITION))
{
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.
......
......@@ -279,11 +279,16 @@ 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,
const char *from_path,
const char *to_path);
#else
#define partition_key_modified(X,Y) 0
#endif
......
......@@ -192,10 +192,8 @@ 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;
......@@ -292,7 +290,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);
......@@ -988,4 +986,53 @@ bool Sql_cmd_alter_table_truncate_partition::execute(THD *thd)
DBUG_RETURN(error);
}
/**
Move a table specified in the CONVERT TABLE <table_name> TO PARTITION ...
to the new partition.
@param lpt A structure containing parameters regarding to the statement
ALTER TABLE ... TO PARTITION ...
@param part_file_name a file name of the partition being added
@return false on success, true on error
*/
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;
const char *partition_name=
thd->lex->part_info->curr_part_elem->partition_name;
if (create_partition_name(part_file_name, sizeof(part_file_name), path,
partition_name, NORMAL_PART_NAME, false))
return true;
char from_file_name[FN_REFLEN+1];
build_table_filename(from_file_name, sizeof(from_file_name),
table_from->db.str, table_from->table_name.str, "", 0);
handler *file= get_new_handler(nullptr, thd->mem_root,
table_from->table->file->ht);
if (unlikely(!file))
return true;
close_all_tables_for_name(thd, table_from->table->s,
HA_EXTRA_PREPARE_FOR_RENAME, nullptr);
bool res= file->ha_rename_table(from_file_name, part_file_name);
if (res)
my_error(ER_ERROR_ON_RENAME, MYF(0), from_file_name,
part_file_name, my_errno);
delete file;
return res;
}
#endif /* WITH_PARTITION_STORAGE_ENGINE */
......@@ -875,7 +875,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)
{
......@@ -9688,7 +9687,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);
......
......@@ -7290,6 +7290,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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment