summaryrefslogtreecommitdiff
path: root/mysql-test/suite/versioning/r/select.result
blob: 39a5880250a41b81b0e5a7a23a6f27908ad59051 (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
set @@session.time_zone='+00:00';
select ifnull(max(transaction_id), 0) into @start_trx_id from information_schema.innodb_vtq;
create procedure if not exists verify_vtq()
begin
set @i= 0;
select
@i:= @i + 1 as No,
transaction_id > 0 as A,
commit_id > transaction_id as B,
begin_timestamp > '1-1-1 0:0:0' as C,
commit_timestamp >= begin_timestamp as D
from information_schema.innodb_vtq
where transaction_id > @start_trx_id;
select ifnull(max(transaction_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
create function if not exists default_engine()
returns varchar(255)
deterministic
begin
declare e varchar(255);
select lower(engine) from information_schema.engines where support='DEFAULT' into e;
return e;
end~~
create function if not exists sys_datatype()
returns varchar(255)
deterministic
begin
if default_engine() = 'innodb' then
return 'bigint unsigned';
elseif default_engine() = 'myisam' then
return 'timestamp(6)';
end if;
return NULL;
end~~
create function if not exists sys_commit_ts(sys_field varchar(255))
returns varchar(255)
deterministic
begin
if default_engine() = 'innodb' then
return concat('vtq_commit_ts(', sys_field, ')');
elseif default_engine() = 'myisam' then
return sys_field;
end if;
return NULL;
end~~
create procedure if not exists innodb_verify_vtq(recs int)
begin
declare i int default 1;
if default_engine() = 'innodb' then
call verify_vtq;
elseif default_engine() = 'myisam' then
create temporary table tmp (No int, A bool, B bool, C bool, D bool);
while i <= recs do
insert into tmp values (i, 1, 1, 1, 1);
set i= i + 1;
end while;
select * from tmp;
drop table tmp;
end if;
end~~
create procedure test_01()
begin
declare engine varchar(255) default default_engine();
declare sys_type varchar(255) default sys_datatype();
declare fields varchar(255) default sys_commit_ts('sys_start');
set @str= concat('
  create table t1(
    x int unsigned,
    y int unsigned,
    sys_start ', sys_type, ' generated always as row start,
    sys_end ', sys_type, ' generated always as row end,
    period for system_time (sys_start, sys_end))
  with system versioning
  engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1 (x, y) values
(0, 100),
(1, 101),
(2, 102),
(3, 103),
(4, 104),
(5, 105),
(6, 106),
(7, 107),
(8, 108),
(9, 109);
set @t0= now(6);
if engine = 'innodb' then
select sys_start from t1 limit 1 into @x0;
end if;
delete from t1 where x = 3;
delete from t1 where x > 7;
insert into t1(x, y) values(3, 33);
select sys_start from t1 where x = 3 and y = 33 into @t1;
if engine = 'innodb' then
set @x1= @t1;
select vtq_commit_ts(@x1) into @t1;
end if;
select x, y from t1;
select x as ASOF_x, y from t1 for system_time as of timestamp @t0;
select x as FROMTO_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
select x as BETWAND_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
select x as FROMTO_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
select x as BETWAND_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
select x as ALL_x, y from t1 for system_time all;
if engine = 'innodb' then
select x as ASOF2_x, y from t1 for system_time as of transaction @x0;
select x as FROMTO2_x, y from t1 for system_time from transaction 0 to transaction @x1;
select x as BETWAND2_x, y from t1 for system_time between transaction 0 and transaction @x1;
select x as FROMTO2_ext_x, y from t1 for system_time transaction from 0 to @x1;
select x as BETWAND2_ext_x, y from t1 for system_time transaction between 0 and @x1;
else
select x as ASOF2_x, y from t1 for system_time as of timestamp @t0;
select x as FROMTO2_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
select x as BETWAND2_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
select x as FROMTO2_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
select x as BETWAND2_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;  
end if;
drop table t1;
end~~
create or replace procedure test_02()
begin
declare engine varchar(255) default default_engine();
declare sys_type varchar(255) default sys_datatype();
declare fields varchar(255) default sys_commit_ts('sys_start');
set @str0= concat('(
    x int,
    y int,
    sys_start ', sys_type, ' generated always as row start,
    sys_end ', sys_type, ' generated always as row end,
    period for system_time (sys_start, sys_end))
  with system versioning
  engine ', engine);
set @str= concat('create or replace table t1', @str0);
prepare stmt from @str; execute stmt; drop prepare stmt;
set @str= concat('create or replace table t2', @str0);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1 values (1, 1), (1, 2), (1, 3), (4, 4), (5, 5);
insert into t2 values (1, 2), (2, 1), (3, 1);
set @t0= now(6);
select t1.x as IJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x;
select t1.x as LJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x;
select t1.x as RJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x;
delete from t1;
delete from t2;
select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x
query for system_time as of timestamp @t0;
select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x
query for system_time as of timestamp @t0;
select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x
query for system_time as of timestamp @t0;
drop table t1;
drop table t2;
end~~
call test_01();
x	y
0	100
1	101
2	102
4	104
5	105
6	106
7	107
3	33
ASOF_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
FROMTO_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
BETWAND_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
3	33
FROMTO_ext_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
BETWAND_ext_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
3	33
ALL_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
3	33
ASOF2_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
FROMTO2_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
BETWAND2_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
3	33
FROMTO2_ext_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
BETWAND2_ext_x	y
0	100
1	101
2	102
3	103
4	104
5	105
6	106
7	107
8	108
9	109
3	33
call test_02();
IJ1_x1	y1	x2	y2
1	1	1	2
1	2	1	2
1	3	1	2
LJ1_x1	y1	x2	y2
1	1	1	2
1	2	1	2
1	3	1	2
4	4	NULL	NULL
5	5	NULL	NULL
RJ1_x1	y1	x2	y2
1	1	1	2
1	2	1	2
1	3	1	2
NULL	NULL	2	1
NULL	NULL	3	1
IJ2_x1	y1	x2	y2
1	1	1	2
1	2	1	2
1	3	1	2
LJ2_x1	y1	x2	y2
1	1	1	2
1	2	1	2
1	3	1	2
4	4	NULL	NULL
5	5	NULL	NULL
RJ2_x1	y1	x2	y2
1	1	1	2
1	2	1	2
1	3	1	2
NULL	NULL	2	1
NULL	NULL	3	1
create table t1(
A int
) with system versioning;
insert into t1 values(1);
select * from t1;
A
1
create or replace table t1 (x int);
insert into t1 values (1);
select * from t1 for system_time all;
ERROR HY000: System Versioning required: `FOR SYSTEM_TIME` query
create or replace table t1 (x int) with system versioning;
insert into t1 values (1);
select * from t1 for system_time all for update;
ERROR HY000: Versioned SELECT write-locking of history rows
create or replace table t1 (a int not null auto_increment primary key) with system versioning;
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
a
create or replace table t1 (a int) with system versioning;
create or replace table t2 (a int) with system versioning;
insert into t1 values(1);
insert into t2 values(1);
create view v1 as select * from t2 inner join t1 using (a);
select * from v1;
a
1
drop view v1;
create or replace table t1 (a int) with system versioning;
insert into t1 values (1);
create view vt1 as select a from t1;
select * from t1 natural join vt1;
a
1
drop view vt1;
create or replace table t1(x int) with system versioning;
select * from (t1 as r left join t1 as u using (x)), t1;
x	x
create or replace table t1 (a int) with system versioning;
insert into t1 values (1);
create trigger read_end after update on t1
for each row set @end = old.sys_trx_end;
update t1 set a=2;
select @end;
@end
MAX_RESULT
create or replace table t1 (a int) with system versioning;
create or replace table t2 (b int) with system versioning;
insert into t1 values (1);
insert into t2 values (2);
select * from (select * from t1 cross join t2) as tmp;
a	b
1	2
select * from (select * from (select * from t1 cross join t2) as tmp1) as tmp2;
a	b
1	2
select * from (select * from t1 cross join t2 for system_time as of timestamp '0-0-0') as tmp;
a	b
create or replace table t1(a1 int) with system versioning;
create or replace table t2(a2 int) with system versioning;
insert into t1 values(1),(2);
insert into t2 values(1),(2);
select * from t1 for system_time all natural left join t2 for system_time all;
a1	a2
1	1
2	1
1	2
2	2
create or replace table t1(a1 int) with system versioning;
create or replace table t2(a2 int) with system versioning;
insert into t1 values(1),(2);
insert into t2 values(1),(2);
create or replace view v1 as select a1 from t1;
select * from v1 natural join t2;
a1	a2
1	1
2	1
1	2
2	2
select * from v1 natural left join t2;
a1	a2
1	1
2	1
1	2
2	2
select * from v1 natural right join t2;
a2	a1
1	1
2	1
1	2
2	2
create or replace table t1 (a int) with system versioning;
insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (3);
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
a	a
2	1
3	1
2	2
3	2
2	3
3	3
1	NULL
create or replace table t1 (x int) with system versioning;
create or replace table t2 (y int) with system versioning;
insert into t1 values (1), (2), (3);
delete from t1 where x = 3;
insert into t2 values (1);
select * from t1, t2 query for system_time all;
x	y
1	1
2	1
3	1
select * from t1 for system_time all, t2 for system_time all query for system_time all;
ERROR HY000: Unused clause: 'QUERY FOR SYSTEM_TIME'
drop view v1;
drop table t1, t2;
call innodb_verify_vtq(27);
No	A	B	C	D
1	1	1	1	1
2	1	1	1	1
3	1	1	1	1
4	1	1	1	1
5	1	1	1	1
6	1	1	1	1
7	1	1	1	1
8	1	1	1	1
9	1	1	1	1
10	1	1	1	1
11	1	1	1	1
12	1	1	1	1
13	1	1	1	1
14	1	1	1	1
15	1	1	1	1
16	1	1	1	1
17	1	1	1	1
18	1	1	1	1
19	1	1	1	1
20	1	1	1	1
21	1	1	1	1
22	1	1	1	1
23	1	1	1	1
24	1	1	1	1
25	1	1	1	1
26	1	1	1	1
27	1	1	1	1
drop procedure test_01;
drop procedure test_02;
drop procedure verify_vtq;
drop procedure innodb_verify_vtq;
drop function default_engine;
drop function sys_commit_ts;
drop function sys_datatype;