1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
|
--echo #
--echo # Scenario 1:
--echo # Create a normal table, rebuild and truncate will clear the instant
--echo # information
--echo #
--eval CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT) ROW_FORMAT=$row_format
INSERT INTO t1 VALUES(0, 1), (0, 2), (0, 3), (0, 4), (0, 5);
let $new_cols = 1;
let $instant_add_column = ALTER TABLE t1 ADD COLUMN c1 INT DEFAULT 10;
--source ../mysql-test/suite/innodb/include/instant_add_column_exec_and_verify.inc
# An ALTER TABLE which requires rebuild
let $new_cols = 0;
let $instant_add_column = ALTER TABLE t1 ADD COLUMN c2 INT DEFAULT 20, ADD KEY(c2);
--source ../mysql-test/suite/innodb/include/instant_add_column_exec_and_verify.inc
# Should be empty now
SELECT count(*) FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) FROM information_schema.innodb_columns WHERE has_default = 1;
INSERT INTO t1(a, b) VALUES(0, 1), (0, 2), (0, 3), (0, 4), (0, 5);
let $new_cols = 1;
let $instant_add_column = ALTER TABLE t1 ADD COLUMN c3 INT DEFAULT 10;
--source ../mysql-test/suite/innodb/include/instant_add_column_exec_and_verify.inc
# TRUNCATE TABLE should rebuild the table too
let $new_cols = 0;
let $instant_add_column = TRUNCATE TABLE t1;
--source ../mysql-test/suite/innodb/include/instant_add_column_exec_and_verify.inc
# Should be empty now
SELECT count(*) FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) FROM information_schema.innodb_columns WHERE has_default = 1;
CHECK TABLE t1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
--echo #
--echo # Scenario 2:
--echo # Create a partitioned table, rebuild and truncate will clear the instant
--echo # information
--echo #
--eval CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT) ROW_FORMAT=$row_format PARTITION BY HASH(a) PARTITIONS 3;
INSERT INTO t1 VALUES(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8);
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_columns WHERE has_default = 1;
ALTER TABLE t1 ADD COLUMN c1 INT DEFAULT 10;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 3` FROM information_schema.innodb_columns WHERE has_default = 1;
# This will rebuild all partitions
ALTER TABLE t1 ADD COLUMN c2 INT DEFAULT 20, ALGORITHM = COPY;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_columns WHERE has_default = 1;
INSERT INTO t1(b, c1, c2) SELECT b, c1, c2 FROM t1;
ALTER TABLE t1 ADD COLUMN c3 INT DEFAULT 30;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 3` FROM information_schema.innodb_columns WHERE has_default = 1;
# This will rebuild all partitions
TRUNCATE TABLE t1;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_columns WHERE has_default = 1;
CHECK TABLE t1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
--echo #
--echo # Scenario 3:
--echo # Create a partitioned table, ALTER TABLE ... PARTITION will clear the
--echo # instant information
--echo #
# Range partitioned table
--eval CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT) ROW_FORMAT=$row_format PARTITION BY RANGE (a) (PARTITION p1 VALUES LESS THAN (10), PARTITION p2 VALUES LESS THAN (20), PARTITION p3 VALUES LESS THAN (30));
INSERT INTO t1 VALUES(1, 1), (2, 2), (11, 11), (12, 12), (21, 21), (22, 22), (26, 26), (27, 27);
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_columns WHERE has_default = 1;
ALTER TABLE t1 ADD COLUMN c INT DEFAULT 100;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 3` FROM information_schema.innodb_columns WHERE has_default = 1;
# The new partition should have instant column information
ALTER TABLE t1 ADD PARTITION (PARTITION p4 VALUES LESS THAN(40));
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 4` FROM information_schema.innodb_columns WHERE has_default = 1;
SELECT instant_cols FROM information_schema.innodb_tables WHERE name LIKE '%p4%';
# The new partition should have instant column information
ALTER TABLE t1 REORGANIZE PARTITION p3 INTO (PARTITION p31 VALUES LESS THAN(25), PARTITION p32 VALUES LESS THAN(30));
SELECT * FROM t1 WHERE a > 20 AND a < 30;
SELECT * FROM t1 WHERE a > 10 AND a < 20;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 5` FROM information_schema.innodb_columns WHERE has_default = 1;
SELECT instant_cols FROM information_schema.innodb_tables WHERE name LIKE '%p3%';
# The truncated partition should not have instant information
ALTER TABLE t1 TRUNCATE PARTITION p1;
SELECT * FROM t1 WHERE a < 10;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 5` FROM information_schema.innodb_columns WHERE has_default = 1;
SELECT instant_cols FROM information_schema.innodb_tables WHERE name LIKE '%p1%';
# Truncate all partitions, the table instant information should be clean
ALTER TABLE t1 TRUNCATE PARTITION p1, p2, p31, p32, p4;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_columns WHERE has_default = 1;
INSERT INTO t1(a, b) VALUES(1, 1), (2, 2), (11, 11), (12, 12), (21, 21), (22, 22), (26, 26), (27, 27);
SELECT c FROM t1 GROUP BY c;
ALTER TABLE t1 ADD COLUMN d INT DEFAULT 100;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 5` FROM information_schema.innodb_columns WHERE has_default = 1;
ALTER TABLE t1 TRUNCATE PARTITION p1;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 5` FROM information_schema.innodb_columns WHERE has_default = 1;
SELECT instant_cols FROM information_schema.innodb_tables WHERE name LIKE '%p1%';
# Drop all partitions except p1, the table information should be clean,
# because p1 is a new partition
ALTER TABLE t1 DROP PARTITION p2, p4;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 3` FROM information_schema.innodb_columns WHERE has_default = 1;
ALTER TABLE t1 DROP PARTITION p31, p32;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 1` FROM information_schema.innodb_columns WHERE has_default = 1;
CHECK TABLE t1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
# HASH partitioned table
--eval CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT) ROW_FORMAT=$row_format PARTITION BY HASH(a) PARTITIONS 3;
INSERT INTO t1 VALUES(0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8);
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_columns WHERE has_default = 1;
ALTER TABLE t1 ADD COLUMN c1 INT DEFAULT 10;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 3` FROM information_schema.innodb_columns WHERE has_default = 1;
# ADD PARTITION will rebuild the whole table, and instant information should be
# clean for each partition
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 5` FROM information_schema.innodb_columns WHERE has_default = 1;
ALTER TABLE t1 ADD COLUMN c2 INT DEFAULT 20;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 10` FROM information_schema.innodb_columns WHERE has_default = 1;
# COALESCE PARTITION will rebuild the whole table, and instant information
# should be clean for each partition
ALTER TABLE t1 COALESCE PARTITION 2;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 6` FROM information_schema.innodb_columns WHERE has_default = 1;
# Verify it once more
ALTER TABLE t1 ADD COLUMN c3 INT DEFAULT 30;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 9` FROM information_schema.innodb_columns WHERE has_default = 1;
# ADD PARTITION will rebuild the whole table, and instant information should be
# clean for each partition
ALTER TABLE t1 ADD PARTITION PARTITIONS 2;
SELECT count(*) AS `Expect 0` FROM information_schema.innodb_tables WHERE instant_cols != 0;
SELECT count(*) AS `Expect 15` FROM information_schema.innodb_columns WHERE has_default = 1;
SELECT * FROM t1;
CHECK TABLE t1;
SHOW CREATE TABLE t1;
DROP TABLE t1;
|