Skip to content

Commit 6972480

Browse files
midenokvuvova
authored andcommitted
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>
1 parent 7da721b commit 6972480

17 files changed

+2411
-326
lines changed

mysql-test/suite/atomic/alter_partition,innodb.rdiff

Lines changed: 304 additions & 14 deletions
Large diffs are not rendered by default.

mysql-test/suite/atomic/alter_partition.result

Lines changed: 432 additions & 16 deletions
Large diffs are not rendered by default.

mysql-test/suite/atomic/alter_partition.test

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,30 @@ let $crash_points='crash_create_before_create_frm',
5555
#let $crash_count= 1;
5656
#let $crash_points= 'crash_convert_partition_10';
5757

58-
let $statement_count= 1;
59-
let $statements= 'ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1';
58+
let $statement_count= 2;
59+
let $statements= 'ALTER TABLE t1 CONVERT PARTITION p1 TO TABLE tp1',
60+
'ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40)';
6061

61-
#let $statement_count=1;
62-
#let $statements='CREATE OR REPLACE TABLE t1 SELECT * from const_table';
62+
#let $statement_count= 1;
63+
#let $statements= 'ALTER TABLE t1 CONVERT TABLE tp2 TO PARTITION p2 values less than (40)';
6364

6465
--delimiter $
65-
create or replace procedure prepare_table()
66+
create or replace procedure prepare_table(r int)
6667
begin
6768
create or replace table t1 (x int)
6869
with system versioning
6970
partition by range(x) (
7071
partition p0 values less than (10),
7172
partition p1 values less than (20),
72-
partition pn values less than maxvalue);
73+
partition pn values less than (30));
7374
insert into t1 values (2), (12), (22);
75+
76+
if r > 1 then
77+
create or replace table tp2 (x int)
78+
with system versioning;
79+
insert into tp2 values (32), (39);
80+
end if;
81+
7482
flush tables;
7583
end $
7684
--delimiter ;
@@ -95,7 +103,7 @@ while ($r < $statement_count)
95103
let $crash=`select ELT($c, $crash_points)`;
96104

97105
--eval set @@default_storage_engine=$default_engine
98-
call prepare_table;
106+
eval call prepare_table($r);
99107
if (!$c)
100108
{
101109
lock tables t1 write;
@@ -147,6 +155,11 @@ while ($r < $statement_count)
147155
show create table tp1;
148156
--error 0, ER_NO_SUCH_TABLE
149157
select * from tp1;
158+
--replace_result $default_engine DEFAULT_ENGINE ' PAGE_CHECKSUM=1' ''
159+
--error 0, ER_NO_SUCH_TABLE
160+
show create table tp2;
161+
--error 0, ER_NO_SUCH_TABLE
162+
select * from tp2;
150163
# Drop the tables. The warnings will show what was dropped
151164
--disable_warnings
152165
drop table t1;

mysql-test/suite/parts/inc/partition_fail_t2.inc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,40 @@
22
# To be used with WL#4445: EXCHANGE PARTITION WITH TABLE.
33
--eval $create_statement2
44
--eval $insert_statement2
5-
SHOW CREATE TABLE t2;
6-
--sorted_result
7-
SELECT * FROM t2;
85
--eval $create_statement
96
--eval $insert_statement
10-
--echo # State before failure
7+
--let $dbug_flag= `select @@session.debug_dbug`
8+
--echo # $dbug_flag: BEFORE failure
119
--replace_result #p# #P#
10+
if (!$DATADIR)
11+
{
12+
--let $DATADIR= `SELECT @@datadir;`
13+
}
1214
--list_files $DATADIR/test
1315
SHOW CREATE TABLE t1;
1416
--sorted_result
1517
SELECT * FROM t1;
18+
SHOW CREATE TABLE t2;
19+
--sorted_result
20+
SELECT * FROM t2;
1621
# accept all errors
1722
--disable_abort_on_error
1823
--replace_regex /#sql-exchange-[0-9a-f_\-]*/#sql-exchange/i
1924
--eval $fail_statement
2025
--enable_abort_on_error
21-
--echo # State after failure
26+
--echo # $dbug_flag: AFTER failure
2227
--replace_result #p# #P#
2328
--list_files $DATADIR/test
2429
SHOW CREATE TABLE t1;
2530
--sorted_result
2631
SELECT * FROM t1;
2732
DROP TABLE t1;
33+
--error 0, ER_NO_SUCH_TABLE
2834
SHOW CREATE TABLE t2;
2935
--sorted_result
36+
--error 0, ER_NO_SUCH_TABLE
3037
SELECT * FROM t2;
38+
# TODO: everything fails with ER_NO_SUCH_TABLE
39+
# but DROP TABLE fails with ER_BAD_TABLE_ERROR! Why?
40+
--error 0, ER_BAD_TABLE_ERROR
3141
DROP TABLE t2;

mysql-test/suite/parts/r/alter_table.result

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,87 @@ ERROR 42000: Can't open table
2929
DROP VIEW v1;
3030
DROP TABLE t1, t2;
3131
#
32-
# MDEV-22166 MIGRATE PARTITION: move out partition into a table
32+
# MDEV-22165 CONVERT PARTITION: move in partition from existing table
33+
#
34+
create or replace table tp1 (a int);
35+
create or replace table t1 (a int)
36+
partition by hash (a) partitions 2;
37+
alter table t1 convert table tp1 to partition p2;
38+
ERROR HY000: CONVERT TABLE TO PARTITION can only be used on RANGE/LIST partitions
39+
create or replace table t1 (a int)
40+
partition by range (a)
41+
(partition p0 values less than (0));
42+
alter table t1 convert table non_existent to partition p1 values less than (10);
43+
ERROR 42S02: Table 'test.non_existent' doesn't exist
44+
alter table t1 convert table tp1 to partition p1 values less than (10);
45+
show create table tp1;
46+
ERROR 42S02: Table 'test.tp1' doesn't exist
47+
show create table t1;
48+
Table Create Table
49+
t1 CREATE TABLE `t1` (
50+
`a` int(11) DEFAULT NULL
51+
) ENGINE=X DEFAULT CHARSET=latin1
52+
PARTITION BY RANGE (`a`)
53+
(PARTITION `p0` VALUES LESS THAN (0) ENGINE = X,
54+
PARTITION `p1` VALUES LESS THAN (10) ENGINE = X)
55+
create table tp2 (x int);
56+
alter table t1 convert table tp2 to partition p2 values less than (20);
57+
ERROR HY000: Tables have different definitions
58+
show create table tp2;
59+
Table Create Table
60+
tp2 CREATE TABLE `tp2` (
61+
`x` int(11) DEFAULT NULL
62+
) ENGINE=X DEFAULT CHARSET=latin1
63+
show create table t1;
64+
Table Create Table
65+
t1 CREATE TABLE `t1` (
66+
`a` int(11) DEFAULT NULL
67+
) ENGINE=X DEFAULT CHARSET=latin1
68+
PARTITION BY RANGE (`a`)
69+
(PARTITION `p0` VALUES LESS THAN (0) ENGINE = X,
70+
PARTITION `p1` VALUES LESS THAN (10) ENGINE = X)
71+
create or replace table tp2 (a int);
72+
insert tp2 values (1), (15), (17);
73+
alter table t1 convert table tp2 to partition p2 values less than (20);
74+
ERROR HY000: Found a row that does not match the partition
75+
delete from tp2;
76+
insert tp2 values (15), (1), (17);
77+
alter table t1 convert table tp2 to partition p2 values less than (20);
78+
ERROR HY000: Found a row that does not match the partition
79+
delete from tp2;
80+
insert tp2 values (15), (17), (1);
81+
alter table t1 convert table tp2 to partition p2 values less than (20);
82+
ERROR HY000: Found a row that does not match the partition
83+
delete from tp2;
84+
insert tp2 values (15), (17);
85+
alter table t1 convert table tp2 to partition p2 values less than (20);
86+
show create table tp2;
87+
ERROR 42S02: Table 'test.tp2' doesn't exist
88+
show create table t1;
89+
Table Create Table
90+
t1 CREATE TABLE `t1` (
91+
`a` int(11) DEFAULT NULL
92+
) ENGINE=X DEFAULT CHARSET=latin1
93+
PARTITION BY RANGE (`a`)
94+
(PARTITION `p0` VALUES LESS THAN (0) ENGINE = X,
95+
PARTITION `p1` VALUES LESS THAN (10) ENGINE = X,
96+
PARTITION `p2` VALUES LESS THAN (20) ENGINE = X)
97+
select * from t1 partition (p2);
98+
a
99+
15
100+
17
101+
create or replace table t1 (a int)
102+
partition by range (a) (
103+
p0 values less than (0),
104+
pn values less than (30));
105+
insert into t1 values (1);
106+
create or replace table tp1 (a int);
107+
insert into tp1 values (2);
108+
alter table t1 convert table tp1 to partition p1 values less than (10);
109+
ERROR HY000: VALUES LESS THAN value must be strictly increasing for each partition
110+
drop tables t1, tp1;
111+
#
112+
# MDEV-22166 CONVERT PARTITION: move out partition into a table
33113
#
34114
create or replace table t1 (x int);
35115
alter table t1 convert partition p1 to table tp1;

0 commit comments

Comments
 (0)