summaryrefslogtreecommitdiff
path: root/mysql-test/main/alter_table_online.result
blob: a1bbc4bb56100fda918b455c7d0207b1ac6c56f6 (plain)
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
connect  con2, localhost, root,,;
connection default;
#
# Test insert
#
# Insert and add column
create or replace table t1 (a int) engine=innodb;
insert t1 values (5);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 add b int NULL, algorithm= copy, lock= none;
connection con2;
insert into t1 values (123), (456), (789);
set debug_sync= 'now SIGNAL end';
connection default;
select * from t1;
a	b
5	NULL
123	NULL
456	NULL
789	NULL
# Insert and add NOT NULL column without default value
create or replace table t1 (a int) engine=innodb;
insert t1 values (5);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 add b int NOT NULL, algorithm= copy, lock= none;
connection con2;
insert into t1 values (123), (456), (789);
set debug_sync= 'now SIGNAL end';
connection default;
Warnings:
Warning	1364	Field 'b' doesn't have a default value
Warning	1364	Field 'b' doesn't have a default value
Warning	1364	Field 'b' doesn't have a default value
select * from t1;
a	b
5	0
123	0
456	0
789	0
# Insert and add a column with a default value
create or replace table t1 (a int) engine=innodb;
insert t1 values (5);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 add b int NOT NULL default (222), algorithm= copy, lock= none;
connection con2;
insert into t1 values (123), (456), (789);
set debug_sync= 'now SIGNAL end';
connection default;
select * from t1;
a	b
5	222
123	222
456	222
789	222
#
# Test update
#
# Update and add a column
create or replace table t1 (a int primary key, b int) engine=innodb;
insert t1 values (1, 22);
insert t1 values (3, 44);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 add c int default(1),
algorithm= copy, lock= none;
connection con2;
update t1 set b= 55 where a = 1;
set debug_sync= 'now SIGNAL end';
connection default;
select * from t1;
a	b	c
1	55	1
3	44	1
#
# Test primary key change
#
# Drop key, add key
create or replace table t1 (a int primary key, b int) engine=innodb;
insert t1 values (1, 22);
insert t1 values (3, 44);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 drop primary key, add primary key(b),
algorithm= copy, lock= none;
connection con2;
update t1 set b= 55 where a = 1;
set debug_sync= 'now SIGNAL end';
connection default;
select * from t1;
a	b
3	44
1	55
# Drop key, add key. Two updates
create or replace table t1 (a int primary key, b int) engine=innodb;
insert t1 values (1, 11);
insert t1 values (2, 22);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 drop primary key, add primary key(b),
algorithm= copy, lock= none;
connection con2;
update t1 set b= 33 where a = 1;
update t1 set b= 44 where a = 2;
set debug_sync= 'now SIGNAL end';
connection default;
select * from t1;
a	b
1	33
2	44
#
# Various tests, see below
#
create or replace table t1 (a int primary key, b int) engine=innodb;
insert t1 values (1, 11);
insert t1 values (2, 22);
insert t1 values (3, 33);
insert t1 values (4, 44);
insert t1 values (5, 55);
insert t1 values (6, 66);
insert t1 values (7, 77);
insert t1 values (8, 88);
insert t1 values (9, 99);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 drop primary key, add primary key(b),
algorithm= copy, lock= none;
connection con2;
# Two updates
update t1 set b= 1001 where a = 1;
update t1 set b= 2002 where a = 2;
# Two updates in transaction
set autocommit = 0;
start transaction;
update t1 set b= 3003 where a = 3;
update t1 set b= 4004 where a = 4;
commit;
set autocommit = 1;
# Second update is rolled back
update t1 set b= 5005 where a = 5;
set autocommit = 0;
start transaction;
update t1 set b= 6006 where a = 6;
rollback;
set autocommit = 1;
# Second execution in transaction fails
set autocommit = 0;
start transaction;
update t1 set b= 7007 where a = 7;
update t1 set a= 8, b= 8008 where a = 8 or a = 9 order by a;
ERROR 23000: Duplicate entry '8' for key 'PRIMARY'
commit;
set autocommit = 1;
select * from t1;
a	b
1	1001
2	2002
3	3003
4	4004
5	5005
6	66
7	7007
8	88
9	99
set debug_sync= 'now SIGNAL end';
connection default;
select * from t1;
a	b
1	1001
2	2002
3	3003
4	4004
5	5005
6	66
7	7007
8	88
9	99
#
# MYISAM. Only Inserts can be tested.
#
create or replace table t1 (a int) engine=myisam;
insert t1 values (5);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 add b int NULL, algorithm= copy, lock= none;
connection con2;
insert into t1 values (123), (456), (789);
set debug_sync= 'now SIGNAL end';
connection default;
select * from t1;
a	b
5	NULL
123	NULL
456	NULL
789	NULL
# Test incompatible changes
create or replace table t1 (a int primary key, b int) engine=innodb;
insert t1 values (1, 22);
insert t1 values (3, 44);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 drop primary key, add primary key(b),
algorithm= copy, lock= none;
connection con2;
update t1 set b= 44 where a = 1;
set debug_sync= 'now SIGNAL end';
connection default;
ERROR 23000: Duplicate entry '44' for key 'PRIMARY'
select * from t1;
a	b
1	44
3	44
# Test log read after EXCLUSIVE lock
# Transaction is started before ALTER, and UPDATE is made.
# Then more UPDATEs.
create or replace table t1 (a int primary key, b int) engine=innodb;
insert t1 values (1, 11);
insert t1 values (2, 22);
insert t1 values (3, 33);
insert t1 values (4, 44);
insert t1 values (5, 55);
set debug_sync= 'alter_table_online_before_lock SIGNAL locking WAIT_FOR end';
set debug_sync= 'alter_table_online_downgraded SIGNAL downgraded';
alter table t1 drop primary key, add primary key(b),
algorithm= copy, lock= none;
connection con2;
begin;
set debug_sync= 'now WAIT_FOR downgraded';
update t1 set b= 111 where a = 1;
set debug_sync= 'now WAIT_FOR locking';
set debug_sync= 'now SIGNAL end';
update t1 set b= 222 where a = 2;
update t1 set b= 333 where a = 3;
update t1 set b= 444 where a = 4;
commit;
update t1 set b= 555 where a = 5;
connection default;
select * from t1;
a	b
1	111
2	222
3	333
4	444
5	555
#
# Test progress report.
#
create or replace table t1 (a int primary key, b int) engine=innodb;
insert t1 values (1, 11);
insert t1 values (2, 22);
insert t1 values (3, 33);
insert t1 values (4, 44);
set debug_sync= 'alter_table_online_before_lock SIGNAL locking WAIT_FOR end';
set debug_sync= 'alter_table_online_downgraded SIGNAL downgraded'
                                             ' WAIT_FOR start_replication';
set debug_sync= 'alter_table_online_progress SIGNAL applied WAIT_FOR proceed'
                                           ' EXECUTE 9';
alter table t1 drop primary key, add primary key(b),
algorithm= copy, lock= none;
connection con2;
set debug_sync= 'now WAIT_FOR downgraded';
update t1 set b= 111 where a = 1;
insert t1 values (5, 55);
update t1 set b= 555 where a = 5;
insert t1 values (6, 66);
update t1 set b= 666 where a = 6;
set debug_sync= 'now SIGNAL start_replication';
# First signal is for log description event.
set debug_sync= 'now WAIT_FOR applied';
select stage, progress from INFORMATION_SCHEMA.PROCESSLIST where id = @con;
stage	progress
3	51.220
set debug_sync= 'now SIGNAL proceed WAIT_FOR applied';
select stage, progress from INFORMATION_SCHEMA.PROCESSLIST where id = @con;
stage	progress
3	61.789
set debug_sync= 'now SIGNAL proceed WAIT_FOR applied';
select stage, progress from INFORMATION_SCHEMA.PROCESSLIST where id = @con;
stage	progress
3	70.325
set debug_sync= 'now SIGNAL proceed WAIT_FOR applied';
select stage, progress from INFORMATION_SCHEMA.PROCESSLIST where id = @con;
stage	progress
3	80.894
set debug_sync= 'now SIGNAL proceed WAIT_FOR applied';
select stage, progress from INFORMATION_SCHEMA.PROCESSLIST where id = @con;
stage	progress
3	89.431
set debug_sync= 'now SIGNAL proceed WAIT_FOR applied';
select stage, progress from INFORMATION_SCHEMA.PROCESSLIST where id = @con;
stage	progress
3	100.000
set debug_sync= 'now SIGNAL proceed WAIT_FOR locking';
begin;
update t1 set b= 222 where a = 2;
update t1 set b= 333 where a = 3;
update t1 set b= 444 where a = 4;
commit;
set debug_sync= 'now SIGNAL end WAIT_FOR applied';
select stage, progress from INFORMATION_SCHEMA.PROCESSLIST where id = @con;
stage	progress
4	33.333
set debug_sync= 'now SIGNAL proceed WAIT_FOR applied';
select stage, progress from INFORMATION_SCHEMA.PROCESSLIST where id = @con;
stage	progress
4	66.667
set debug_sync= 'now SIGNAL proceed WAIT_FOR applied';
select stage, progress from INFORMATION_SCHEMA.PROCESSLIST where id = @con;
stage	progress
4	100.000
set debug_sync= 'now SIGNAL proceed';
connection default;
select * from t1;
a	b
1	111
2	222
3	333
4	444
5	555
6	666
#
# Test system versioning
#
create or replace table t1 (a int primary key, b int);
insert t1 values (1, 22);
insert t1 values (3, 44);
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
set timestamp = 1;
alter table t1 add system versioning,
algorithm= copy, lock= none;
connection con2;
set timestamp = 2;
update t1 set b= 55 where a = 1;
set timestamp = 3;
insert into t1 values (6, 77);
set debug_sync= 'now SIGNAL end';
connection default;
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) NOT NULL,
  `b` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`)
) ENGINE=*SUBSTITUTED* DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
select *, UNIX_TIMESTAMP(row_start), UNIX_TIMESTAMP(row_end) from t1 for system_time all;
a	b	UNIX_TIMESTAMP(row_start)	UNIX_TIMESTAMP(row_end)
1	22	1.000000	2.000000
1	55	2.000000	2147483647.999999
3	44	1.000000	2147483647.999999
6	77	3.000000	2147483647.999999
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 drop system versioning,
algorithm= copy, lock= none;
connection con2;
update t1 set b= 88 where a = 1;
set debug_sync= 'now SIGNAL end';
connection default;
# Can't UPDATE versioned -> plain (and can't DELETE)
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) NOT NULL,
  `b` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`)
) ENGINE=*SUBSTITUTED* DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
select *, UNIX_TIMESTAMP(row_start), UNIX_TIMESTAMP(row_end) from t1 for system_time all;
a	b	UNIX_TIMESTAMP(row_start)	UNIX_TIMESTAMP(row_end)
1	22	1.000000	2.000000
1	55	2.000000	3.000000
1	88	3.000000	2147483647.999999
3	44	1.000000	2147483647.999999
6	77	3.000000	2147483647.999999
connection con2;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 drop system versioning,
algorithm= copy, lock= none;
connection con2;
insert into t1 values (8, 99);
set debug_sync= 'now SIGNAL end';
connection default;
# INSERT versioned -> plain works fine since it is a single versioned op.
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) NOT NULL,
  `b` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`)
) ENGINE=*SUBSTITUTED* DEFAULT CHARSET=latin1
select * from t1;
a	b
1	88
3	44
6	77
8	99
#
# Test ROLLBACK TO SAVEPOINT
#
create or replace table t1 (a int) engine=innodb;
insert t1 values (1), (2);
create or replace table t2 (a int) engine=innodb;
insert t2 values (1), (2);
connection con2;
begin;
update t2 set a= 222 where a = 2;
savepoint savie;
update t2 set a= 111 where a = 1;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 add b int NULL, algorithm= copy, lock= none;
connection con2;
update t1 set a= 123 where a = 1;
savepoint whoopsie;
rollback to savepoint savie;
commit;
set debug_sync= 'now SIGNAL end';
connection default;
select * from t1;
a	b
1	NULL
2	NULL
select * from t2;
a
1
222
create or replace table t1 (a int) engine=innodb;
insert t1 values (1), (2);
create or replace table t2 (a int) engine=innodb;
insert t2 values (1), (2);
connection con2;
begin;
update t2 set a= 222 where a = 2;
savepoint savie;
update t2 set a= 111 where a = 1;
set debug_sync= 'now WAIT_FOR ended';
connection default;
set debug_sync= 'alter_table_copy_end SIGNAL ended WAIT_FOR end';
alter table t1 add b int NULL, algorithm= copy, lock= none;
connection con2;
savepoint whoopsie;
update t1 set a= 123 where a = 1;
select * from t1;
a
123
2
rollback to savepoint whoopsie;
select * from t1;
a
1
2
commit;
set debug_sync= 'now SIGNAL end';
connection default;
select * from t1;
a	b
1	NULL
2	NULL
select * from t2;
a
111
222
# Cleanup
set debug_sync= 'reset';
drop table t1;
drop table t2;