| 1 |
--source include/have_partition.inc |
| 2 |
--source include/have_innodb.inc |
| 3 |
--source include/have_s3.inc |
| 4 |
--source include/have_sequence.inc |
| 5 |
--source create_database.inc |
| 6 |
|
| 7 |
# |
| 8 |
# The purpose of this test is to show how to move an partition from an existing |
| 9 |
# InnoDB partitioned table (t1) to a partitioned table in S3 (archive) |
| 10 |
# |
| 11 |
|
| 12 |
# |
| 13 |
# We start by creating a partioned table in S3 with one existing partion p0 |
| 14 |
# |
| 15 |
|
| 16 |
CREATE TABLE p0 ( |
| 17 |
c1 int primary key, |
| 18 |
c2 int DEFAULT NULL |
| 19 |
) ENGINE=InnoDB; |
| 20 |
insert into p0 select seq,seq from seq_1_to_99; |
| 21 |
|
| 22 |
alter table p0 engine=s3 , rename to archive |
| 23 |
PARTITION BY RANGE (c1) |
| 24 |
(PARTITION p0 VALUES LESS THAN (100)); |
| 25 |
|
| 26 |
show create table archive; |
| 27 |
|
| 28 |
# |
| 29 |
# Then we create the table t1 that contains multiple partitions. |
| 30 |
# Partition p1 is the one that we want to move to 'archive' |
| 31 |
# |
| 32 |
|
| 33 |
CREATE TABLE t1 ( |
| 34 |
c1 int primary key, |
| 35 |
c2 int DEFAULT NULL |
| 36 |
) ENGINE=InnoDB |
| 37 |
PARTITION BY RANGE (c1) |
| 38 |
(PARTITION p1 VALUES LESS THAN (200), |
| 39 |
PARTITION p2 VALUES LESS THAN (300), |
| 40 |
PARTITION p3 VALUES LESS THAN (400)); |
| 41 |
insert into t1 select seq,seq from seq_100_to_399; |
| 42 |
|
| 43 |
# |
| 44 |
# Then it's time to do the real work. |
| 45 |
# |
| 46 |
|
| 47 |
# First we move partition p1 to a normal InnoDB table |
| 48 |
|
| 49 |
create table p1 like t1; |
| 50 |
alter table p1 remove partitioning; |
| 51 |
alter table t1 exchange partition p1 with table p1; |
| 52 |
alter table t1 drop partition p1; |
| 53 |
|
| 54 |
show create table p1; |
| 55 |
select count(*) from p1; |
| 56 |
|
| 57 |
# Then change the table engine to s3 and move it into archive |
| 58 |
|
| 59 |
alter table p1 engine=s3; |
| 60 |
alter table archive add partition (partition p1 values less than (200)); |
| 61 |
alter table archive exchange partition p1 with table p1; |
| 62 |
|
| 63 |
# p1 will be empty as this was the new partition that we just created |
| 64 |
select count(*) from p1; |
| 65 |
drop table p1; |
| 66 |
|
| 67 |
# |
| 68 |
# The p1 partition has now been moved from t1 to archive. Check the result |
| 69 |
# |
| 70 |
|
| 71 |
show create table t1; |
| 72 |
show create table archive; |
| 73 |
select count(*) from t1; |
| 74 |
select count(*) from archive; |
| 75 |
drop table t1,archive; |
| 76 |
|
| 77 |
# |
| 78 |
# clean up |
| 79 |
# |
| 80 |
--source drop_database.inc |