summaryrefslogtreecommitdiffstats
path: root/mysql-test/suite/versioning/r/create.result
blob: c9d68f15e575a9f58f9ba083a22622325f852684 (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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
create table t1 (
x1 int unsigned,
Sys_start SYS_DATATYPE as row start invisible comment 'start',
Sys_end SYS_DATATYPE as row end invisible comment 'end',
period for system_time (Sys_start, Sys_end)
) with system versioning;
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x1` int(10) unsigned DEFAULT NULL,
  `Sys_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START INVISIBLE COMMENT 'start',
  `Sys_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END INVISIBLE COMMENT 'end',
  PERIOD FOR SYSTEM_TIME (`Sys_start`, `Sys_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
select table_catalog,table_schema,table_name,table_type,version,table_rows,data_free,auto_increment,check_time,table_collation,checksum,create_options,table_comment from information_schema.tables where table_name='t1';
table_catalog	def
table_schema	test
table_name	t1
table_type	SYSTEM VERSIONED
version	10
table_rows	0
data_free	0
auto_increment	NULL
check_time	NULL
table_collation	latin1_swedish_ci
checksum	NULL
create_options	
table_comment	
select table_catalog,table_schema,table_name,column_name,ordinal_position,column_default,character_maximum_length,character_octet_length,character_set_name,collation_name,column_key,extra,column_comment,is_generated,generation_expression from information_schema.columns where table_name='t1';
table_catalog	def
table_schema	test
table_name	t1
column_name	x1
ordinal_position	1
column_default	NULL
character_maximum_length	NULL
character_octet_length	NULL
character_set_name	NULL
collation_name	NULL
column_key	
extra	
column_comment	
is_generated	NEVER
generation_expression	NULL
table_catalog	def
table_schema	test
table_name	t1
column_name	Sys_start
ordinal_position	2
column_default	NULL
character_maximum_length	NULL
character_octet_length	NULL
character_set_name	NULL
collation_name	NULL
column_key	
extra	STORED GENERATED, INVISIBLE
column_comment	start
is_generated	ALWAYS
generation_expression	ROW START
table_catalog	def
table_schema	test
table_name	t1
column_name	Sys_end
ordinal_position	3
column_default	NULL
character_maximum_length	NULL
character_octet_length	NULL
character_set_name	NULL
collation_name	NULL
column_key	
extra	STORED GENERATED, INVISIBLE
column_comment	end
is_generated	ALWAYS
generation_expression	ROW END
# Implicit fields test
create or replace table t1 (
x2 int unsigned
) with system versioning;
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x2` int(10) unsigned DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
x3 int unsigned,
Sys_start timestamp(6) as row start invisible,
Sys_end timestamp(6) as row end invisible,
period for system_time (x, Sys_end)
) with system versioning;
ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end`
create or replace table t1 (
x4 int unsigned,
Sys_start timestamp(6) as row start invisible,
Sys_end2 timestamp(6) as row end invisible,
period for system_time (Sys_start, Sys_end)
) with system versioning;
ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end2`
create or replace table t1 (
x5 int unsigned,
Sys_start timestamp(6) as row start invisible,
Sys_end timestamp(6) as row end invisible,
period for system_time (Sys_start, x)
) with system versioning;
ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end`
create or replace table t1 (
x6 int unsigned,
period for system_time (Sys_start, Sys_end)
) with system versioning;
ERROR HY000: Wrong parameters for `t1`: missing 'AS ROW START'
create or replace table t1 (
x7 int unsigned,
Sys_start timestamp(6) as row start invisible,
Sys_end timestamp(6) as row end invisible,
period for system_time (Sys_start, Sys_end)
);
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
create or replace table t1 (
x8 int unsigned,
Sys_start timestamp(6) as row start invisible,
Sys_end timestamp(6) as row end invisible,
period for system_time (sys_insert, sys_remove)
) with system versioning;
ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end`
create or replace table t1 (
x9 int unsigned,
Sys_start timestamp(6) as row start invisible,
Sys_end timestamp(6) as row end invisible,
period for system_time (Sys_start, Sys_end)
);
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
create or replace table t1 (
x10 int unsigned,
Sys_start timestamp(6) as row start invisible,
Sys_end timestamp(6) as row end invisible,
period for system_time (Sys_start, Sys_start)
);
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
create or replace table t1 (
x11 int unsigned,
Sys_start bigint unsigned as row start invisible,
Sys_end timestamp(6) as row end invisible,
period for system_time (Sys_start, Sys_end)
) with system versioning;
Got one of the listed errors
create or replace table t1 (
x12 int unsigned,
Sys_start timestamp(6) as row start invisible,
Sys_end bigint unsigned as row end invisible,
period for system_time (Sys_start, Sys_end)
) with system versioning;
Got one of the listed errors
create or replace table t1 (
x13 int unsigned,
Sys_start bigint as row start invisible,
Sys_end bigint unsigned as row end invisible,
period for system_time (Sys_start, Sys_end)
) with system versioning engine innodb;
ERROR HY000: `Sys_start` must be of type BIGINT(20) UNSIGNED for system-versioned table `t1`
create or replace table t1 (
x14 int unsigned,
Sys_start bigint unsigned as row start invisible,
Sys_end bigint as row end invisible,
period for system_time (Sys_start, Sys_end)
) with system versioning engine innodb;
ERROR HY000: `Sys_end` must be of type BIGINT(20) UNSIGNED for system-versioned table `t1`
create or replace table t1 (
x15 int with system versioning,
B int
);
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x15` int(11) DEFAULT NULL,
  `B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
x16 int with system versioning,
B int
) with system versioning;
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x16` int(11) DEFAULT NULL,
  `B` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
x17 int,
B int without system versioning
);
create or replace table t1 (
x18 int,
B int without system versioning
) with system versioning;
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x18` int(11) DEFAULT NULL,
  `B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
x19 int with system versioning,
B int without system versioning
);
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x19` int(11) DEFAULT NULL,
  `B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
x20 int with system versioning,
B int without system versioning
) with system versioning;
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x20` int(11) DEFAULT NULL,
  `B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
x21 int without system versioning
);
create or replace table t1 (
x22 int without system versioning
) with system versioning;
ERROR HY000: Table `t1` must have at least one versioned column
create or replace table t1 (a int) with system versioning;
create table tt1 like t1;
show create table tt1;
Table	Create Table
tt1	CREATE TABLE `tt1` (
  `a` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
drop table tt1;
create temporary table tt1 like t1;
Warnings:
Warning	1105	System versioning is stripped from temporary `test.tt1`
# Temporary is stripped from versioning
show create table tt1;
Table	Create Table
tt1	CREATE TEMPORARY TABLE `tt1` (
  `a` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
# CREATE TABLE ... SELECT
create or replace table t1 (x23 int) with system versioning;
create or replace table t0(
y int,
st timestamp(6) as row start,
en timestamp(6) as row end,
period for system_time (st, en)
) with system versioning;
## For non-versioned table:
### 1. invisible fields are not included
create or replace table t2 as select * from t1;
show create table t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `x23` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
### 2. all visible fields are included
create or replace table t3 as select * from t0;
select * from t0;
y	st	en
show create table t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `y` int(11) DEFAULT NULL,
  `st` timestamp(6) NOT NULL,
  `en` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
## For versioned table
insert into t1 values (1);
select row_start from t1 into @row_start;
Warnings:
Warning	1287	'<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
insert into t0 (y) values (2);
select st from t0 into @st;
Warnings:
Warning	1287	'<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
create or replace table t2 with system versioning as select * from t1;
show create table t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `x23` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
#### invisible fields are not copied
select * from t2;
x23
1
select * from t2 where row_start <= @row_start;
x23
### 2. source table with visible system fields, target with invisible
create or replace table t3 with system versioning as select * from t0;
show create table t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `y` int(11) DEFAULT NULL,
  `st` timestamp(6) NOT NULL,
  `en` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
select * from t3 where y > 2;
y	st	en
select y from t3 where st = @st and row_start > @st;
y
2
### 3. source and target table with visible system fields
create or replace table t3 (
st timestamp(6) as row start invisible,
en timestamp(6) as row end invisible,
period for system_time (st, en)
) with system versioning as select * from t0;
show create table t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `y` int(11) DEFAULT NULL,
  `st` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE,
  `en` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE,
  PERIOD FOR SYSTEM_TIME (`st`, `en`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
select y from t3;
y
2
select y from t3 where st = @st;
y
### 4. system fields not or wrongly selected
create or replace table t3 with system versioning select x23 from t1;
show create table t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `x23` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
select * from t3;
x23
1
create or replace table t3 with system versioning select x23, row_start from t1;
ERROR 42S21: Duplicate column name 'row_start'
create or replace table t3 with system versioning select x23, row_end from t1;
ERROR 42S21: Duplicate column name 'row_end'
# Prepare checking for historical row
delete from t1;
select row_end from t1 for system_time all into @row_end;
Warnings:
Warning	1287	'<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
delete from t0;
select en from t0 for system_time all into @en;
Warnings:
Warning	1287	'<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
## Combinations of versioned + non-versioned
create or replace table t2 (y int);
insert into t2 values (3);
create or replace table t3 with system versioning select * from t1 for system_time all, t2;
show create table t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `x23` int(11) DEFAULT NULL,
  `y` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
select * from t3 for system_time all;
x23	y
1	3
select * from t3 for system_time all where row_start = @row_start and row_end = @row_end;
x23	y
create or replace table t2 like t0;
insert into t2 (y) values (1), (2);
delete from t2 where y = 2;
create or replace table t3 select * from t2 for system_time all;
select st, en from t3 where y = 1 into @st, @en;
Warnings:
Warning	1287	'<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
select y from t2 for system_time all where st = @st and en = @en;
y
1
select st, en from t3 where y = 2 into @st, @en;
Warnings:
Warning	1287	'<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead
select y from t2 for system_time all where st = @st and en = @en;
y
2
## Default engine detection
create or replace table t1 (x25 int) with system versioning engine NON_DEFAULT_ENGINE;
create or replace table t2
as select x25, row_start, row_end from t1 for system_time all;
show create table t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `x25` int(11) DEFAULT NULL,
  `row_start` timestamp(6) NOT NULL,
  `row_end` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
create or replace table t2 with system versioning
as select x25, row_start rs, row_end re from t1;
show create table t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `x25` int(11) DEFAULT NULL,
  `rs` timestamp(6) NOT NULL,
  `re` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
x26 int,
st bigint unsigned as row start,
en bigint unsigned as row end,
period for system_time (st, en)
) with system versioning engine innodb;
create or replace table t2 with system versioning engine myisam
as select * from t1;
show create table t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `x26` int(11) DEFAULT NULL,
  `st` bigint(20) unsigned NOT NULL,
  `en` bigint(20) unsigned NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (x27 int, id int) with system versioning engine NON_DEFAULT_ENGINE;
create or replace table t2 (b int, id int);
create or replace table t3 with system versioning
as select t2.b, t1.x27, t1.row_start rs, t1.row_end re from t2 inner join t1 on t2.id=t1.id;
show create table t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `b` int(11) DEFAULT NULL,
  `x27` int(11) DEFAULT NULL,
  `rs` timestamp(6) NOT NULL,
  `re` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
## Errors
create or replace temporary table t (x28 int) with system versioning;
ERROR HY000: System-versioned tables do not support CREATE TEMPORARY TABLE
create or replace table t1 (
x29 int unsigned,
Sys_start0 timestamp(6) as row start invisible,
Sys_start timestamp(6) as row start invisible,
Sys_end timestamp(6) as row end invisible,
period for system_time (Sys_start, Sys_end)
) with system versioning;
ERROR HY000: Duplicate ROW START column `Sys_start`
create or replace table t1 (
x29 int unsigned,
Sys_end0 timestamp(6) as row end invisible,
Sys_start timestamp(6) as row start invisible,
Sys_end timestamp(6) as row end invisible,
period for system_time (Sys_start, Sys_end)
) with system versioning;
ERROR HY000: Duplicate ROW END column `Sys_end`
## System fields detection
create or replace table t1 (x30 int) with system versioning;
create or replace table t2 (
y int,
st timestamp(6) as row start invisible,
en timestamp(6) as row end invisible,
period for system_time (st, en)
) with system versioning;
create or replace table t3
as select x30, y, row_start, row_end, st, en from t1, t2;
show create table t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `x30` int(11) DEFAULT NULL,
  `y` int(11) DEFAULT NULL,
  `row_start` timestamp(6) NOT NULL,
  `row_end` timestamp(6) NOT NULL,
  `st` timestamp(6) NOT NULL,
  `en` timestamp(6) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
create or replace table t3 (
y int,
st timestamp(6) as row start invisible,
en timestamp(6) as row end invisible,
period for system_time (st, en)
) with system versioning
as select x30, y, row_start, row_end, st, en from t1, t2;
show create table t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `x30` int(11) DEFAULT NULL,
  `y` int(11) DEFAULT NULL,
  `row_start` timestamp(6) NOT NULL,
  `row_end` timestamp(6) NOT NULL,
  `st` timestamp(6) GENERATED ALWAYS AS ROW START INVISIBLE,
  `en` timestamp(6) GENERATED ALWAYS AS ROW END INVISIBLE,
  PERIOD FOR SYSTEM_TIME (`st`, `en`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
# MDEV-14828 Server crashes in JOIN::prepare / setup_fields on 2nd execution of PS [#437]
create or replace table t1 (x int) with system versioning;
prepare bad from 'create or replace table t2 with system versioning as select * from t1';
execute bad;
execute bad;
execute bad;
execute bad;
execute bad;
execute bad;
execute bad;
execute bad;
# bad is good.
# MDEV-15413 Unexpected errors upon CREATE TABLE .. WITH SYSTEM VERSIONING AS SELECT ...
create or replace table t1 with system versioning as select 1 as i;
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `i` int(1) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (i int) with system versioning as select 1 as i;
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `i` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
a int,
row_start bigint as row start,
row_end bigint as row end,
period for system_time (row_start, row_end)
) engine=innodb with system versioning;
ERROR HY000: `row_start` must be of type BIGINT(20) UNSIGNED for system-versioned table `t1`
create or replace table t1 (
a int,
row_start bigint as row start,
row_end bigint as row end,
period for system_time (row_start, row_end)
) engine=myisam with system versioning;
ERROR HY000: `row_start` must be of type BIGINT(20) UNSIGNED for system-versioned table `t1`
create table t (
a int,
row_start datetime(6) generated always as row start,
row_end datetime(6) generated always as row end,
period for system_time(row_start, row_end)
) with system versioning;
ERROR HY000: `row_start` must be of type TIMESTAMP(6) for system-versioned table `t`
# MDEV-16490 It's possible to make a system versioned table without any versioning field
create or replace table t1 (x int without system versioning)
with system versioning
select 1 as y;
create or replace table t1 (x int without system versioning)
with system versioning
select 1 as x;
ERROR HY000: Table `t1` must have at least one versioned column
drop tables t0, t1, t2, t3;
#
# MDEV-23968 CREATE TEMPORARY TABLE .. LIKE (system versioned table) returns error if unique index is defined in the table
#
create table t1 (id int primary key, index(row_start)) with system versioning;
ERROR 42000: Key column 'row_start' doesn't exist in table
create table t1 (id int primary key, index(row_end)) with system versioning;
ERROR 42000: Key column 'row_end' doesn't exist in table
create table t1 (id int, primary key(id, row_end, row_end)) with system versioning;
ERROR 42000: Key column 'row_end' doesn't exist in table
create table t1 (id int primary key) with system versioning;
create temporary table t2 like t1;
Warnings:
Warning	1105	System versioning is stripped from temporary `test.t2`
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
show create table t2;
Table	Create Table
t2	CREATE TEMPORARY TABLE `t2` (
  `id` int(11) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop temporary table t2;
create or replace table t1 (
a int,
row_start timestamp(6) as row start,
row_end timestamp(6) as row end,
period for system_time (row_start, row_end),
index(row_start),
index(row_end),
primary key(row_end, a, row_start),
index(row_end, row_start, a)) with system versioning;
create temporary table t2 like t1;
Warnings:
Warning	1105	System versioning is stripped from temporary `test.t2`
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) NOT NULL,
  `row_start` timestamp(6) GENERATED ALWAYS AS ROW START,
  `row_end` timestamp(6) GENERATED ALWAYS AS ROW END,
  PRIMARY KEY (`row_end`,`a`,`row_start`),
  KEY `row_start` (`row_start`),
  KEY `row_end` (`row_end`),
  KEY `row_end_2` (`row_end`,`row_start`,`a`),
  PERIOD FOR SYSTEM_TIME (`row_start`, `row_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
show create table t2;
Table	Create Table
t2	CREATE TEMPORARY TABLE `t2` (
  `a` int(11) NOT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop temporary table t2;
drop table t1;
#
# MDEV-16857 system-invisible row_end is displayed in SHOW INDEX
#
create or replace table t1 (id int primary key, x int) with system versioning;
select table_schema, table_name, non_unique, index_schema, index_name, seq_in_index, column_name
from information_schema.statistics where table_name = 't1';
table_schema	table_name	non_unique	index_schema	index_name	seq_in_index	column_name
test	t1	0	test	PRIMARY	1	id
show index from t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_comment	Ignored
t1	0	PRIMARY	1	id	#	#	#	#	#	#			NO
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `id` int(11) NOT NULL,
  `x` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
drop table t1;
#
# MDEV-26928 Column-inclusive WITH SYSTEM VERSIONING doesn't work with explicit system fields
#
create or replace table t1 (x int, y int with system versioning);
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
  `y` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
create or replace table t1 (
x int, y int with system versioning,
row_start timestamp(6) as row start,
row_end timestamp(6) as row end,
period for system_time(row_start, row_end));
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
  `y` int(11) DEFAULT NULL,
  `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`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci WITH SYSTEM VERSIONING
drop table t1;
#
# MDEV-27452 TIMESTAMP(0) system field is allowed for certain creation of system-versioned table
#
create or replace table t (
a int,
s timestamp as row start,
e timestamp as row end,
period for system_time (s, e))
with system versioning;
ERROR HY000: `s` must be of type TIMESTAMP(6) for system-versioned table `t`
create or replace table t (
a int with system versioning,
s timestamp as row start,
e timestamp as row end,
period for system_time (s, e));
ERROR HY000: `s` must be of type TIMESTAMP(6) for system-versioned table `t`
create or replace table t (
a int with system versioning,
b int with system versioning,
s timestamp(6) as row start,
e timestamp(6) as row end,
period for system_time (s, e));
insert into t () values (),();
drop table t;