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
|
select @@system_versioning_alter_history;
create table t(
a int
);
show create table t;
--error ER_VERS_NOT_VERSIONED
alter table t drop system versioning;
alter table t add system versioning;
show create table t;
--error ER_VERS_ALTER_NOT_ALLOWED
alter table t add column y int;
--error ER_VERS_ALTER_ENGINE_PROHIBITED
alter table t engine innodb;
alter table t drop system versioning;
show create table t;
set system_versioning_alter_history= keep;
alter table t add system versioning;
--error ER_CANT_DROP_FIELD_OR_KEY
alter table t drop system versioning, drop column row_start;
alter table t drop system versioning;
--error ER_VERS_FIELD_WRONG_TYPE
alter table t
add column trx_start bigint(20) unsigned as row start invisible,
add column trx_end bigint(20) unsigned as row end invisible,
add period for system_time(trx_start, trx_end),
add system versioning;
--error ER_VERS_FIELD_WRONG_TYPE
alter table t
add column trx_start timestamp as row start invisible,
add column trx_end timestamp as row end invisible,
add period for system_time(trx_start, trx_end),
add system versioning;
--error ER_PARSE_ERROR
alter table t
add column trx_start timestamp(6) not null as row start invisible,
add column trx_end timestamp(6) not null as row end invisible,
add period for system_time(trx_start, trx_end),
add system versioning;
alter table t
add column trx_start timestamp(6) as row start invisible,
add column trx_end timestamp(6) as row end invisible,
add period for system_time(trx_start, trx_end),
add system versioning;
show create table t;
--error ER_MISSING
alter table t drop system versioning;
alter table t drop column trx_start, drop column trx_end;
select row_start from t;
alter table t drop system versioning;
show create table t;
--error ER_VERS_NOT_VERSIONED
alter table t add column trx_start timestamp(6) as row start;
alter table t add system versioning;
show create table t;
alter table t add column b int;
show create table t;
alter table t add column c int;
show create table t;
alter table t add column d int first;
show create table t;
alter table t add column e int after d;
show create table t;
alter table t drop column a;
show create table t;
create or replace table t (
a int,
row_start timestamp(6) as row start invisible,
row_end timestamp(6) as row end invisible,
period for system_time(row_start, row_end))
with system versioning;
select * from t for system_time all;
--error ER_MISSING
alter table t drop column row_start;
--error ER_MISSING
alter table t drop column row_end;
alter table t drop column row_start, drop column row_end;
select * from t for system_time all;
show create table t;
--error ER_CANT_DROP_FIELD_OR_KEY
alter table t drop column row_start;
--error ER_CANT_DROP_FIELD_OR_KEY
alter table t drop column row_end;
create or replace table t (
a int,
row_start timestamp(6) as row start invisible,
row_end timestamp(6) as row end invisible,
period for system_time(row_start, row_end))
with system versioning;
select * from t for system_time all;
alter table t drop column row_start, drop column row_end;
select * from t for system_time all;
create or replace table t(
a int
);
insert into t values(1);
alter table t add system versioning;
show create table t;
insert into t values(2);
select * from t for system_time all;
select * from t;
update t set a=3 where a=1;
select * from t;
select * from t for system_time all;
select row_start from t where a=3 into @tm;
alter table t add column b int;
select @tm=row_start from t where a=3;
show create table t;
select * from t;
select * from t for system_time all;
alter table t drop system versioning;
select * from t;
show create table t;
--error ER_VERS_NOT_VERSIONED
alter table t modify a int with system versioning;
--error ER_VERS_NOT_VERSIONED
alter table t modify a int without system versioning;
alter table t add system versioning;
alter table t modify a int without system versioning;
show create table t;
alter table t modify a int with system versioning;
show create table t;
# TODO: move TRX_ID cases to separate test
-- source suite/versioning/common.inc
create or replace table t(
a int
) engine=innodb;
alter table t
add column trx_start timestamp(6) as row start invisible,
add column trx_end timestamp(6) as row end invisible,
add period for system_time(trx_start, trx_end),
add system versioning;
show create table t;
--echo # Issue #211: drop of system columns required before drop system versioning
alter table t drop column trx_start, drop column trx_end;
show create table t;
alter table t drop system versioning;
insert into t values(1);
call verify_vtq;
alter table t
add column trx_start bigint(20) unsigned as row start invisible,
add column trx_end bigint(20) unsigned as row end invisible,
add period for system_time(trx_start, trx_end),
add system versioning;
call verify_vtq;
show create table t;
alter table t drop column trx_start, drop column trx_end;
call verify_vtq;
alter table t drop system versioning, algorithm=copy;
call verify_vtq;
alter table t add system versioning, algorithm=copy;
call verify_vtq;
show create table t;
update t set a= 2;
select * from t for system_time all;
alter table t add column b int, algorithm=copy;
show create table t;
select * from t;
call verify_vtq;
alter table t drop column b, algorithm=copy;
show create table t;
select * from t for system_time all;
call verify_vtq;
## FIXME: #414 IB: inplace for VERS_TIMESTAMP versioning
if (0)
{
alter table t drop system versioning, algorithm=inplace;
call verify_vtq;
alter table t add system versioning, algorithm=inplace;
call verify_vtq;
show create table t;
update t set a= 1;
select * from t for system_time all;
call verify_vtq;
alter table t add column b int, algorithm=inplace;
show create table t;
select * from t;
call verify_vtq;
alter table t drop column b, algorithm=inplace;
show create table t;
select * from t for system_time all;
}
## FIXME END
alter table t drop system versioning, algorithm=copy;
show create table t;
call verify_vtq;
# nullable autoinc test w/o versioning
create or replace table t (a int);
insert t values (1),(2),(3),(4);
alter table t add b int auto_increment null unique;
select * from t;
drop table t;
create or replace table t (a int) with system versioning engine=innodb;
insert into t values (1), (2), (3);
delete from t where a<3;
--error ER_DUP_ENTRY, ER_DUP_ENTRY
alter table t add b int not null unique;
--error ER_UNSUPPORTED_EXTENSION, ER_UNSUPPORTED_EXTENSION
alter table t add b int auto_increment unique;
alter table t add b int auto_increment null unique;
select * from t;
select * from t for system_time all;
insert into t values (4, 0);
select * from t for system_time all;
create or replace table t (a int) with system versioning;
insert into t values (1), (2), (3);
delete from t where a<3;
--error ER_DUP_ENTRY, ER_DUP_ENTRY
alter table t add b int not null unique;
--error ER_UNSUPPORTED_EXTENSION, ER_UNSUPPORTED_EXTENSION
alter table t add b int auto_increment unique;
alter table t add b int auto_increment null unique;
select * from t;
select * from t for system_time all;
insert into t values (4, 0);
select * from t for system_time all;
create or replace table t (a int, b int primary key, c int unique) with system versioning;
insert t values (1,2,3),(1,3,4),(1,4,5);
alter table t drop system versioning;
show create table t;
select * from t;
create or replace table t (
a int,
row_start timestamp(6) as row start invisible,
row_end timestamp(6) as row end invisible,
period for system_time(row_start, row_end)
) with system versioning;
--error ER_VERS_ALTER_SYSTEM_FIELD
alter table t change column row_start asdf timestamp(6);
insert into t values (1);
--error ER_VERS_ALTER_SYSTEM_FIELD
alter table t modify column row_start bigint unsigned;
## These experimental options are now disabled
--error ER_WRONG_VALUE_FOR_VAR
set system_versioning_alter_history= SURVIVE;
--error ER_WRONG_VALUE_FOR_VAR
set system_versioning_alter_history= 'DROP';
if (0)
{
create or replace table t (a int) with system versioning engine innodb;
insert into t values (1);
update t set a = 2;
select * from t for system_time all;
alter table t add column b int;
select * from t for system_time all;
create or replace table t (a int) with system versioning engine myisam;
insert into t values (1);
update t set a = 2;
select * from t for system_time all;
alter table t add column b int;
select * from t for system_time all;
create or replace table non_empty (
a int,
row_start bigint(20) unsigned,
row_end bigint(20) unsigned
) engine innodb;
insert into non_empty values (1, 100, 200);
--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
alter table non_empty
change column row_start row_start bigint(20) unsigned as row start invisible;
--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
alter table non_empty
change column row_end row_end bigint(20) unsigned as row end invisible;
drop table non_empty;
create or replace table t (a int primary key) with system versioning;
insert into t values (1);
update t set a=2;
alter table t drop primary key, add primary key (a), drop system versioning;
select * from t;
--replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM
show create table t;
create or replace table t (a int primary key) with system versioning;
insert into t values (1);
update t set a=2;
alter table t drop system versioning;
select * from t;
--replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM
show create table t;
call verify_vtq;
}
create or replace table t (a int) with system versioning;
--error ER_VERS_ALREADY_VERSIONED
alter table t add system versioning;
--error ER_VERS_ALREADY_VERSIONED
alter table t add system versioning, drop system versioning;
set @@system_versioning_alter_history=keep;
create or replace table t(x int, y int) with system versioning engine=innodb;
alter table t modify y int without system versioning;
insert into t values(1, 1);
update t set y=2;
--echo # MDEV-14681 Bogus ER_UNSUPPORTED_EXTENSION
create or replace table t1 (pk int auto_increment unique) with system versioning;
insert into t1 values (1);
delete from t1;
alter table t1 engine=myisam;
--echo # MDEV-14692 crash in MDL_context::upgrade_shared_lock()
create or replace temporary table t (a int);
--error ER_VERS_TEMPORARY
alter table t change column if exists b c bigint unsigned generated always as row start;
--error ER_VERS_TEMPORARY
alter table t change column if exists b c bigint unsigned generated always as row end;
--error ER_VERS_TEMPORARY
alter table t add system versioning;
drop table t;
--echo # MDEV-14744 trx_id-based and transaction-based mixup in assertion
create or replace table t (c text) engine=innodb with system versioning;
show create table t;
alter table t add fulltext key (c);
create or replace table t (a int) with system versioning;
--error ER_VERS_TABLE_MUST_HAVE_COLUMNS
alter table t drop column a;
--error ER_CANT_DROP_FIELD_OR_KEY
alter table t drop column a, drop column a;
create or replace table t1 (row_start int);
--error ER_DUP_FIELDNAME
alter table t1 with system versioning;
create or replace table t1 (row_end int);
--error ER_DUP_FIELDNAME
alter table t1 with system versioning;
--error ER_DUP_FIELDNAME
create or replace table t1 (a int, row_start int) with system versioning;
create or replace table t1 (a int) with system versioning;
--error ER_DUP_FIELDNAME
set statement system_versioning_alter_history=keep for
alter table t1 add column row_start int;
--error ER_DUP_FIELDNAME
set statement system_versioning_alter_history=keep for
alter table t1 add column row_start timestamp(6);
--echo # MDEV-14798 Add, drop system versioning semantic and syntax
create or replace table t (
a int,
row_start timestamp(6) generated always as row start,
row_end timestamp(6) generated always as row end,
period for system_time(row_start, row_end)
) with system versioning;
show create table t;
alter table t
drop column row_start,
drop column row_end,
drop period for system_time,
drop system versioning;
show create table t;
--error ER_VERS_NOT_VERSIONED
alter table t drop period for system_time;
create or replace table t (
a int,
row_start timestamp(6) generated always as row start,
row_end timestamp(6) generated always as row end,
period for system_time(row_start, row_end)
) with system versioning;
--error ER_MISSING
alter table t drop period for system_time;
--error ER_MISSING
alter table t drop column sys_trx_start, drop period for system_time;
--error ER_MISSING
alter table t drop column sys_trx_end, drop period for system_time;
--error ER_VERS_ALREADY_VERSIONED
alter table t add period for system_time(sys_trx_start, sys_trx_end);
drop database test;
create database test;
|