1 # Include file to test PARTITION EXCHANGE usable with different engines
2 # Written by Mattias.Jonsson@Sun.Com
4 --echo #
Test with AUTO_INCREMENT
6 (a INT NOT NULL AUTO_INCREMENT PRIMARY
KEY,
9 PARTITION BY
HASH (a) PARTITIONS 4;
10 CREATE
TABLE t LIKE tp;
11 ALTER
TABLE t REMOVE PARTITIONING;
14 INSERT INTO tp (b) VALUES ("One"), ("Two"), ("Three"), ("Four"), ("Five"),
15 ("Six"), ("Seven"), ("Eight"), ("Nine"), ("Ten"), ("Eleven"), ("Twelwe");
18 # Archive handles auto inc by only allowing increasing values,
19 # so this must be inserted before a higher value is inserted.
20 INSERT INTO tp VALUES (41,
"One hundred one");
22 INSERT INTO tp VALUES (97,
"Ninety seven");
25 INSERT INTO tp VALUES (111,
"One hundred eleven");
29 INSERT INTO tp VALUES (101,
"One hundred one");
32 INSERT INTO t (b) VALUES ("Thirteen");
36 INSERT INTO t (b) VALUES ("Twenty five");
39 INSERT INTO t (b) VALUES ("Twenty one");
43 INSERT INTO t (b) VALUES ("Twenty five");
48 INSERT INTO t (b) VALUES ("Fifty five");
49 DELETE FROM tp WHERE a = 111;
50 DELETE FROM t WHERE a = 55;
54 UPDATE tp SET a = 41 WHERE a = 101;
55 UPDATE t SET a = 17 WHERE a = 25;
62 SELECT PARTITION_NAME, IF(TABLE_ROWS,
'YES',
'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='
test' AND TABLE_NAME = 'tp';
63 SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='
test' AND TABLE_NAME = 't';
64 ALTER
TABLE tp EXCHANGE PARTITION p1 WITH
TABLE t;
70 SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='
test' AND TABLE_NAME = 'tp';
71 SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='
test' AND TABLE_NAME = 't';
72 SELECT * FROM tp
ORDER BY a;
73 SELECT * FROM t
ORDER BY a;
78 # set a DEBUG_SYNC after open table and before verifying is done
79 # Test that one can read from the table but not write, test that one can both
80 # read and write to the partition
81 # Verify that one must close the other instances of the table before the rename
82 # takes place (i.e. no need for LOCK_open)
83 # Test that it is not possible to drop, create, truncate either the tables or
85 # Test that it waits for ongoing transactions
97 PARTITION BY RANGE (a)
98 (PARTITION p0 VALUES LESS THAN (100),
99 PARTITION p1 VALUES LESS THAN MAXVALUE);
100 eval CREATE
TABLE tsp
104 PARTITION BY RANGE (a)
105 SUBPARTITION BY
HASH(a)
106 (PARTITION p0 VALUES LESS THAN (100)
109 PARTITION p1 VALUES LESS THAN MAXVALUE
125 PARTITION BY RANGE (a)
126 (PARTITION p0 VALUES LESS THAN (100),
127 PARTITION p1 VALUES LESS THAN MAXVALUE);
128 eval CREATE
TABLE tsp
133 PARTITION BY RANGE (a)
134 SUBPARTITION BY
HASH(a)
135 (PARTITION p0 VALUES LESS THAN (100)
138 PARTITION p1 VALUES LESS THAN MAXVALUE
143 INSERT INTO t VALUES (1, "First value"), (3, "Three"), (5, "Five"), (99, "End of values");
144 INSERT INTO tp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
145 INSERT INTO tsp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164");
151 --echo
# Start by testing read/write locking
154 connect(con1, localhost, root,,);
156 SET DEBUG_SYNC=
'swap_partition_after_compare_tables SIGNAL swap_in_progress WAIT_FOR goto_verification';
157 SET DEBUG_SYNC=
'swap_partition_first_row_read SIGNAL swap_in_progress WAIT_FOR goto_wait';
158 SET DEBUG_SYNC=
'swap_partition_after_wait SIGNAL swap_in_progress WAIT_FOR goto_rename';
159 SET DEBUG_SYNC=
'swap_partition_before_rename SIGNAL swap_in_progress WAIT_FOR test_done';
160 send ALTER
TABLE tp EXCHANGE PARTITION p0 WITH
TABLE t;
164 SET DEBUG_SYNC=
'now WAIT_FOR swap_in_progress';
165 --echo # select from t and select/update/
delete/insert from tp should work
166 SELECT * FROM t WHERE a = 99;
167 SELECT * FROM tp WHERE a = 61;
168 --echo # any write (update/
delete/insert) into t or tp should fail
169 SET SESSION lock_wait_timeout=1;
172 --error ER_LOCK_WAIT_TIMEOUT
173 UPDATE tp SET a = 53, b = concat(
"Fifty three, was ", b) WHERE a = 63;
175 --error ER_LOCK_WAIT_TIMEOUT
176 INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted");
179 --error ER_LOCK_WAIT_TIMEOUT
180 DELETE FROM tp WHERE a = 59;
184 --error ER_LOCK_WAIT_TIMEOUT
185 UPDATE t SET a = 53, b =
"Fifty three, was three" WHERE a = 3;
187 --error ER_LOCK_WAIT_TIMEOUT
188 INSERT INTO t VALUES (63,
"Sixty three, new"), (59,
"To be deleted");
191 --error ER_LOCK_WAIT_TIMEOUT
192 DELETE FROM t WHERE a = 3;
194 --error ER_LOCK_WAIT_TIMEOUT
195 eval ALTER
TABLE t ENGINE = $engine;
196 --error ER_LOCK_WAIT_TIMEOUT
197 eval ALTER
TABLE tp ENGINE = $engine;
199 SHOW CREATE
TABLE tp;
200 SET DEBUG_SYNC=
'now SIGNAL goto_verification';
201 SET DEBUG_SYNC=
'now WAIT_FOR swap_in_progress';
202 --echo # select from t and select/update/
delete/insert from tp should work
203 SELECT * FROM t WHERE a = 99;
204 SELECT * FROM tp WHERE a = 61;
207 --error ER_LOCK_WAIT_TIMEOUT
208 UPDATE tp SET a = 43, b = concat(
"Fifty three, was ", b) WHERE a = 63;
210 --error ER_LOCK_WAIT_TIMEOUT
211 INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
214 --error ER_LOCK_WAIT_TIMEOUT
215 DELETE FROM tp WHERE a = 59;
217 --echo # any write (update/
delete/insert) into t should fail
220 --error ER_LOCK_WAIT_TIMEOUT
221 UPDATE t SET a = 53, b =
"Fifty three, was three" WHERE a = 3;
223 --error ER_LOCK_WAIT_TIMEOUT
224 INSERT INTO t VALUES (63,
"Sixty three, new"), (59,
"To be deleted");
227 --error ER_LOCK_WAIT_TIMEOUT
228 DELETE FROM t WHERE a = 3;
230 --error ER_LOCK_WAIT_TIMEOUT
231 eval ALTER
TABLE t ENGINE = $engine;
232 --error ER_LOCK_WAIT_TIMEOUT
233 eval ALTER
TABLE tp ENGINE = $engine;
235 SHOW CREATE
TABLE tp;
236 SET DEBUG_SYNC=
'now SIGNAL goto_wait';
237 SET DEBUG_SYNC=
'now WAIT_FOR swap_in_progress';
238 --echo # Both tables should now be under exclusive lock, even SHOW should fail
239 --error ER_LOCK_WAIT_TIMEOUT
240 SELECT * FROM t WHERE a = 99;
241 --error ER_LOCK_WAIT_TIMEOUT
242 SELECT * FROM tp WHERE a = 61;
245 --error ER_LOCK_WAIT_TIMEOUT
246 UPDATE tp SET a = 53, b = concat(
"Fifty three, was ", b) WHERE a = 63;
248 --error ER_LOCK_WAIT_TIMEOUT
249 INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
252 --error ER_LOCK_WAIT_TIMEOUT
253 DELETE FROM tp WHERE a = 59;
257 --error ER_LOCK_WAIT_TIMEOUT
258 UPDATE t SET a = 53, b =
"Fifty three, was three" WHERE a = 3;
260 --error ER_LOCK_WAIT_TIMEOUT
261 INSERT INTO t VALUES (63,
"Sixty three, new"), (59,
"To be deleted");
264 --error ER_LOCK_WAIT_TIMEOUT
265 DELETE FROM t WHERE a = 3;
267 --error ER_LOCK_WAIT_TIMEOUT
269 --error ER_LOCK_WAIT_TIMEOUT
270 SHOW CREATE
TABLE tp;
271 --error ER_LOCK_WAIT_TIMEOUT
272 eval ALTER
TABLE t ENGINE = $engine;
273 --error ER_LOCK_WAIT_TIMEOUT
274 eval ALTER
TABLE tp ENGINE = $engine;
275 SET DEBUG_SYNC=
'now SIGNAL goto_rename';
276 SET DEBUG_SYNC=
'now WAIT_FOR swap_in_progress';
277 --echo # Both tables should now be under exclusive lock
278 --error ER_LOCK_WAIT_TIMEOUT
279 SELECT * FROM t WHERE a = 99;
280 --error ER_LOCK_WAIT_TIMEOUT
281 SELECT * FROM tp WHERE a = 61;
284 --error ER_LOCK_WAIT_TIMEOUT
285 UPDATE tp SET a = 53, b = concat(
"Fifty three, was ", b) WHERE a = 63;
287 --error ER_LOCK_WAIT_TIMEOUT
288 INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted");
291 --error ER_LOCK_WAIT_TIMEOUT
292 DELETE FROM tp WHERE a = 59;
296 --error ER_LOCK_WAIT_TIMEOUT
297 UPDATE t SET a = 53, b =
"Fifty three, was three" WHERE a = 3;
299 --error ER_LOCK_WAIT_TIMEOUT
300 INSERT INTO t VALUES (63,
"Sixty three, new"), (59,
"To be deleted");
303 --error ER_LOCK_WAIT_TIMEOUT
304 DELETE FROM t WHERE a = 3;
306 --error ER_LOCK_WAIT_TIMEOUT
307 eval ALTER
TABLE t ENGINE = $engine;
308 --error ER_LOCK_WAIT_TIMEOUT
309 eval ALTER
TABLE tp ENGINE = $engine;
310 --error ER_LOCK_WAIT_TIMEOUT
312 --error ER_LOCK_WAIT_TIMEOUT
313 SHOW CREATE
TABLE tp;
315 SET DEBUG_SYNC=
'now SIGNAL test_done';
322 --echo # Tables should now be as normal
324 SHOW CREATE
TABLE tp;
325 SELECT * FROM tp WHERE a = 99;
326 SELECT * FROM t WHERE a = 61;
329 UPDATE t SET a = 53, b =
"Fifty three, was sixty three" WHERE a = 63;
331 INSERT INTO t VALUES (63,
"Sixty three, new"), (59,
"To be deleted");
334 DELETE FROM t WHERE a = 59;
338 UPDATE tp SET a = 53, b =
"Fifty three, was three" WHERE a = 3;
340 INSERT INTO tp VALUES (63,
"Sixty three, new"), (59,
"To be deleted");
343 DELETE FROM tp WHERE a = 3;
345 eval ALTER
TABLE t ENGINE = $engine;
346 eval ALTER
TABLE tp ENGINE = $engine;
351 SET DEBUG_SYNC=
'RESET';
353 SHOW CREATE
TABLE tp;
359 DROP
TABLE t, tp, tsp;