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 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
# WL#11250 Support Instant Add Column
--source include/master-slave.inc
--echo # Scenario 1:
--echo # Create a small table, add some columns instantly
--echo #
--source include/rpl_connection_master.inc
CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT);
INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
--source include/sync_slave_sql_with_master.inc
--let $old_table_id_on_slave=`SELECT table_id FROM information_schema.innodb_tables WHERE name='test/t1';`
--source include/rpl_connection_master.inc
# ADD COLUMN INT
let $new_cols = 1;
let $instant_add_column = ALTER TABLE t1 ADD COLUMN c1 INT, ALGORITHM=INSTANT;
--source ../mysql-test/suite/innodb/include/instant_add_column_exec_and_verify.inc
SELECT name, default_value FROM information_schema.innodb_columns WHERE name = 'c1' AND has_default = 1;
INSERT INTO t1(a, c1) VALUES(6, 1);
SELECT count(*) = max(a) FROM t1 WHERE c1 IS NULL;
SELECT c1 FROM t1 WHERE c1 = 1;
SHOW CREATE TABLE t1;
--source include/sync_slave_sql_with_master.inc
--let $new_table_id_on_slave=`SELECT table_id FROM information_schema.innodb_tables WHERE name='test/t1';`
SELECT name, default_value FROM information_schema.innodb_columns WHERE name = 'c1' AND has_default = 1;
SHOW CREATE TABLE t1;
--source include/rpl_connection_master.inc
--let $diff_tables=master:test.t1,slave:test.t1
--source include/diff_tables.inc
if($old_table_id_on_slave == $new_table_id_on_slave)
{
--echo # Table id not changed on slave
}
if($old_table_id_on_slave != $new_table_id_on_slave)
{
--echo # Table id changed on slave
}
--source include/rpl_connection_master.inc
DROP TABLE t1;
--source include/sync_slave_sql_with_master.inc
--echo # Scenario 2:
--echo # Create a small table, add some virtual columns instantly
--echo #
--source include/rpl_connection_master.inc
CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT);
INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
--source include/sync_slave_sql_with_master.inc
--let $old_table_id_on_slave=`SELECT table_id FROM information_schema.innodb_tables WHERE name='test/t1';`
--source include/rpl_connection_master.inc
# ADD VIRTUAL COLUMN
let $new_cols = 1;
let $instant_add_column = ALTER TABLE t1 ADD COLUMN c1 INT, ADD COLUMN c2 FLOAT GENERATED ALWAYS AS ((1.4 * 2.8)) VIRTUAL, ALGORITHM=INSTANT;
--source ../mysql-test/suite/innodb/include/instant_add_column_exec_and_verify.inc
INSERT INTO t1(a, c1) VALUES(6, 1);
SELECT * FROM t1;
SHOW CREATE TABLE t1;
--source include/sync_slave_sql_with_master.inc
--let $new_table_id_on_slave=`SELECT table_id FROM information_schema.innodb_tables WHERE name='test/t1';`
SELECT name, default_value FROM information_schema.innodb_columns WHERE name = 'c1' AND has_default = 1;
SHOW CREATE TABLE t1;
--source include/rpl_connection_master.inc
--let $diff_tables=master:test.t1,slave:test.t1
--source include/diff_tables.inc
if($old_table_id_on_slave == $new_table_id_on_slave)
{
--echo # Table id not changed on slave
}
if($old_table_id_on_slave != $new_table_id_on_slave)
{
--echo # Table id changed on slave
}
--source include/rpl_connection_master.inc
DROP TABLE t1;
--source include/sync_slave_sql_with_master.inc
--echo # Scenario 3:
--echo # Create a small table with RANGE and HASH partition,
--echo # and add INSTANT column
--echo #
--source include/rpl_connection_master.inc
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT)
PARTITION BY RANGE (a)
SUBPARTITION BY HASH (a)
SUBPARTITIONS 3 (
PARTITION p1 values less than (10),
PARTITION p2 values less than (20),
PARTITION p3 values less than maxvalue);
INSERT INTO t1 VALUES(1, 1), (2, 2), (11, 11), (12, 12), (21, 21), (22, 22), (26, 26), (27, 27);
--let $old_table_id_on_master=`SELECT GROUP_CONCAT(table_id) FROM information_schema.innodb_tables WHERE name='test/t1';`
--source include/sync_slave_sql_with_master.inc
--let $old_table_id_on_slave=`SELECT GROUP_CONCAT(table_id) FROM information_schema.innodb_tables WHERE name='test/t1';`
--source include/rpl_connection_master.inc
# ADD VIRTUAL COLUMN
let $new_cols = 1;
let $instant_add_column = ALTER TABLE t1 ADD COLUMN c INT DEFAULT 100;
INSERT INTO t1(a, b) VALUES(5, 5), (6, 6), (28, 28);
SELECT * FROM t1;
SHOW CREATE TABLE t1;
--let $new_table_id_on_master=`SELECT GROUP_CONCAT(table_id) FROM information_schema.innodb_tables WHERE name='test/t1';`
--source include/sync_slave_sql_with_master.inc
--let $new_table_id_on_slave=`SELECT GROUP_CONCAT(table_id) FROM information_schema.innodb_tables WHERE name='test/t1';`
SELECT * FROM t1;
SHOW CREATE TABLE t1;
--source include/rpl_connection_master.inc
--let $diff_tables=master:test.t1,slave:test.t1
--source include/diff_tables.inc
if($old_table_id_on_slave == $new_table_id_on_slave)
{
--echo # Table id not changed on slave
}
if($old_table_id_on_slave != $new_table_id_on_slave)
{
--echo # Table id changed on slave
}
if($old_table_id_on_master == $new_table_id_on_master)
{
--echo # Table id not changed on master
}
if($old_table_id_on_master != $new_table_id_on_master)
{
--echo # Table id changed on master
}
--source include/rpl_connection_master.inc
DROP TABLE t1;
--source include/sync_slave_sql_with_master.inc
--echo # Scenario 4:
--echo # Create a small table and add TIMESTAMP columns instantly
--echo #
--source include/rpl_connection_master.inc
SET @start_session_value = @@session.explicit_defaults_for_timestamp;
# SET explicit_defaults_for_timestamp to OFF
SET @@session.explicit_defaults_for_timestamp=OFF;
SELECT @@session.explicit_defaults_for_timestamp;
CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
INSERT INTO t1 VALUES(1);
--source include/sync_slave_sql_with_master.inc
--let $old_table_id_on_slave=`SELECT table_id FROM information_schema.innodb_tables WHERE name='test/t1';`
--source include/rpl_connection_master.inc
# ADD VIRTUAL COLUMN
let $new_cols = 3;
let $instant_add_column = ALTER TABLE t1 ADD COLUMN c1 TIMESTAMP, ADD COLUMN c2 TIMESTAMP NULL, ADD COLUMN c3 TIMESTAMP DEFAULT CURRENT_TIMESTAMP, ALGORITHM=INSTANT;
--source ../mysql-test/suite/innodb/include/instant_add_column_exec_and_verify.inc
INSERT INTO t1 VALUES(2,NULL,NULL,NULL);
SHOW CREATE TABLE t1;
--replace_column 2 # 4 #
SELECT * FROM t1;
--source include/sync_slave_sql_with_master.inc
--let $new_table_id_on_slave=`SELECT table_id FROM information_schema.innodb_tables WHERE name='test/t1';`
--replace_column 2 # 4 #
SELECT * FROM t1;
SHOW CREATE TABLE t1;
--source include/rpl_connection_master.inc
--let $diff_tables=master:test.t1,slave:test.t1
--source include/diff_tables.inc
if($old_table_id_on_slave == $new_table_id_on_slave)
{
--echo # Table id not changed on slave
}
if($old_table_id_on_slave != $new_table_id_on_slave)
{
--echo # Table id changed on slave
}
DROP TABLE t1;
--source include/sync_slave_sql_with_master.inc
# SET explicit_defaults_for_timestamp to ON
--source include/rpl_connection_master.inc
SET @@session.explicit_defaults_for_timestamp=ON;
SELECT @@session.explicit_defaults_for_timestamp;
CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY);
INSERT INTO t1 VALUES(1);
--source include/sync_slave_sql_with_master.inc
--let $old_table_id_on_slave=`SELECT table_id FROM information_schema.innodb_tables WHERE name='test/t1';`
--source include/rpl_connection_master.inc
# ADD VIRTUAL COLUMN
let $new_cols = 3;
let $instant_add_column = ALTER TABLE t1 ADD COLUMN c1 TIMESTAMP, ADD COLUMN c2 TIMESTAMP NOT NULL, ADD COLUMN c3 TIMESTAMP DEFAULT CURRENT_TIMESTAMP, ALGORITHM=INSTANT;
--source ../mysql-test/suite/innodb/include/instant_add_column_exec_and_verify.inc
INSERT INTO t1 VALUES(2,NULL,'2001-01-01 00:00:00',NULL);
SHOW CREATE TABLE t1;
--replace_column 2 # 4 #
SELECT * FROM t1;
--source include/sync_slave_sql_with_master.inc
--let $new_table_id_on_slave=`SELECT table_id FROM information_schema.innodb_tables WHERE name='test/t1';`
--replace_column 2 # 4 #
SELECT * FROM t1;
SHOW CREATE TABLE t1;
--source include/rpl_connection_master.inc
--let $diff_tables=master:test.t1,slave:test.t1
--source include/diff_tables.inc
if($old_table_id_on_slave == $new_table_id_on_slave)
{
--echo # Table id not changed on slave
}
if($old_table_id_on_slave != $new_table_id_on_slave)
{
--echo # Table id changed on slave
}
DROP TABLE t1;
--source include/sync_slave_sql_with_master.inc
--source include/rpl_connection_master.inc
SET @@session.explicit_defaults_for_timestamp = @start_session_value;
SELECT @@session.explicit_defaults_for_timestamp;
--source include/rpl_end.inc
|