| 1 |
################################################################################ |
| 2 |
# inc/partition_alter_12.inc # |
| 3 |
# # |
| 4 |
# Purpose: # |
| 5 |
# Check ALTER partitioned table and the state of the table afterwards # |
| 6 |
# The partitioning function use the PRIMARY KEY of the table KEY() # |
| 7 |
# # |
| 8 |
# For partitioning methods # |
| 9 |
# PARTITION BY KEY # |
| 10 |
# Enable later : PARTITION BY RANGE/LIST ... SUBPARTITION BY KEY # |
| 11 |
# do # |
| 12 |
# 1. Create the partitioned table # |
| 13 |
# 2. Test Alter Table that changes the key. # |
| 14 |
# - Insert rows into t1 to fill multiple partitions. # |
| 15 |
# - Execute the ALTER TABLE statement # |
| 16 |
# - Check Table status # |
| 17 |
# - [Later] Execute the usability test include/partition_check.inc # |
| 18 |
# - Drop the table t1 # |
| 19 |
# done # |
| 20 |
# # |
| 21 |
# The parameters # |
| 22 |
# $unique -- PRIMARY KEY or UNIQUE INDEXes to be created within the # |
| 23 |
# CREATE TABLE STATEMENT # |
| 24 |
# $alter -- ALTER TABLE statement, which has to be executed # |
| 25 |
# have to be set before sourcing this routine. # |
| 26 |
# Example: # |
| 27 |
# let $unique= , PRIMARY KEY; # |
| 28 |
# let $alter= ALTER TABLE t1 DROP UNIQUE INDEX uidx1; # |
| 29 |
# inc/partition_alter1.inc # |
| 30 |
# # |
| 31 |
# Attention: This routine is created from include/partition_alter_11.inc # |
| 32 |
# So if something has to be changed here it might be necessary to # |
| 33 |
# do it also there. # |
| 34 |
#------------------------------------------------------------------------------# |
| 35 |
# Original Author: debanerj # |
| 36 |
# Original Date: 2015-02-16 # |
| 37 |
# Change Author: # |
| 38 |
# Change Date: # |
| 39 |
# Change: # |
| 40 |
################################################################################ |
| 41 |
|
| 42 |
--disable_warnings |
| 43 |
DROP TABLE IF EXISTS t1; |
| 44 |
--enable_warnings |
| 45 |
|
| 46 |
let $partitioning= ; |
| 47 |
--echo #----------- PARTITION BY KEY |
| 48 |
if ($with_partitioning) { |
| 49 |
let $partitioning= PARTITION BY KEY() PARTITIONS 5; |
| 50 |
} |
| 51 |
eval CREATE TABLE t1 ( |
| 52 |
$column_list |
| 53 |
$unique |
| 54 |
) |
| 55 |
$partitioning; |
| 56 |
|
| 57 |
# The common framework partition_alter_1.inc uses same value/order for all the |
| 58 |
# columns. This makes the distribution accross partition similar even after |
| 59 |
# changing the partition key. For testing primary key() partition and alter |
| 60 |
# using local data. |
| 61 |
#--source suite/parts/inc/partition_alter_1.inc |
| 62 |
|
| 63 |
INSERT INTO t1(f_int1, f_int2) values(100, 200); |
| 64 |
INSERT INTO t1(f_int1, f_int2) values(200, 300); |
| 65 |
INSERT INTO t1(f_int1, f_int2) values(300, 400); |
| 66 |
INSERT INTO t1(f_int1, f_int2) values(400, 500); |
| 67 |
INSERT INTO t1(f_int1, f_int2) values(500, 100); |
| 68 |
|
| 69 |
CHECK TABLE t1; |
| 70 |
|
| 71 |
# Execute ALTER TABLE statement: Error |
| 72 |
if ($expect_inplace_error) { |
| 73 |
--echo Execute ALTER: Expect Error 1845 |
| 74 |
--error 1845 |
| 75 |
eval $alter; |
| 76 |
} |
| 77 |
|
| 78 |
# Execute ALTER TABLE statement: Success |
| 79 |
if ($expect_inplace_error == 0) { |
| 80 |
--echo Execute ALTER: Expect Success |
| 81 |
eval $alter; |
| 82 |
} |
| 83 |
|
| 84 |
CHECK TABLE t1; |
| 85 |
SHOW CREATE TABLE t1; |
| 86 |
|
| 87 |
DROP TABLE t1; |
| 88 |
|
| 89 |
# SUBPARTITION BY KEY (unlike PARTITION BY KEY) does not currently support a |
| 90 |
# default column. Enable when SUBPARTITION BY KEY() is supported. |
| 91 |
if (0) { |
| 92 |
--echo #----------- PARTITION BY RANGE -- SUBPARTITION BY KEY |
| 93 |
if ($with_partitioning) |
| 94 |
{ |
| 95 |
let $partitioning= PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY() |
| 96 |
(PARTITION part1 VALUES LESS THAN (0) |
| 97 |
(SUBPARTITION subpart11, SUBPARTITION subpart12), |
| 98 |
PARTITION part2 VALUES LESS THAN ($max_row_div4) |
| 99 |
(SUBPARTITION subpart21, SUBPARTITION subpart22), |
| 100 |
PARTITION part3 VALUES LESS THAN ($max_row_div2) |
| 101 |
(SUBPARTITION subpart31, SUBPARTITION subpart32), |
| 102 |
PARTITION part4 VALUES LESS THAN $MAX_VALUE |
| 103 |
(SUBPARTITION subpart41, SUBPARTITION subpart42)); |
| 104 |
} |
| 105 |
|
| 106 |
eval CREATE TABLE t1 ( |
| 107 |
$column_list |
| 108 |
$unique |
| 109 |
) |
| 110 |
$partitioning; |
| 111 |
|
| 112 |
#Replace with local INSERT and CHECK as shown above |
| 113 |
#--source suite/parts/inc/partition_alter_1.inc |
| 114 |
DROP TABLE t1; |
| 115 |
|
| 116 |
--echo #----------- PARTITION BY LIST -- SUBPARTITION BY KEY |
| 117 |
if ($with_partitioning) { |
| 118 |
let $partitioning= PARTITION BY LIST(ABS(MOD(f_int1,2))) |
| 119 |
SUBPARTITION BY KEY() SUBPARTITIONS $sub_part_no |
| 120 |
(PARTITION part1 VALUES IN (0), |
| 121 |
PARTITION part2 VALUES IN (1), |
| 122 |
PARTITION part3 VALUES IN (NULL)); |
| 123 |
} |
| 124 |
|
| 125 |
eval CREATE TABLE t1 ( |
| 126 |
$column_list |
| 127 |
$unique |
| 128 |
) |
| 129 |
$partitioning; |
| 130 |
|
| 131 |
#Replace with local INSERT and CHECK as shown above |
| 132 |
#--source suite/parts/inc/partition_alter_1.inc |
| 133 |
DROP TABLE t1; |
| 134 |
} |
| 135 |
|