1--source suite/versioning/engines.inc
2--source suite/versioning/common.inc
3
4replace_result $default_engine ENGINE $sys_datatype_expl SYS_TYPE;
5eval create table t1(
6  x int unsigned,
7  y int unsigned,
8  sys_start $sys_datatype_expl as row start invisible,
9  sys_end $sys_datatype_expl as row end invisible,
10  period for system_time (sys_start, sys_end))
11with system versioning engine=$default_engine;
12
13insert into t1 (x, y) values
14  (0, 100),
15  (1, 101),
16  (2, 102),
17  (3, 103),
18  (4, 104),
19  (5, 105),
20  (6, 106),
21  (7, 107),
22  (8, 108),
23  (9, 109);
24set @t0= now(6);
25select sys_start from t1 limit 1 into @x0;
26
27delete from t1 where x = 3;
28delete from t1 where x > 7;
29
30insert into t1(x, y) values(3, 33);
31select sys_start from t1 where x = 3 and y = 33 into @t1;
32if($MTR_COMBINATION_TRX_ID) {
33  set @x1= @t1;
34  select trt_commit_ts(@x1) into @t1;
35}
36
37select x, y from t1;
38select x as ASOF_x, y from t1 for system_time as of timestamp @t0;
39select x as FROMTO_x, y from t1 for system_time from '1970-01-01 00:00' to timestamp @t1;
40select x as BETWAND_x, y from t1 for system_time between '1970-01-01 00:00' and timestamp @t1;
41select x as ALL_x, y from t1 for system_time all;
42
43if($MTR_COMBINATION_TRX_ID) {
44  select x as ASOF2_x, y from t1 for system_time as of @x0;
45  select x as FROMTO2_x, y from t1 for system_time from @x0 to @x1;
46  select x as BETWAND2_x, y from t1 for system_time between transaction @x0 and transaction @x1;
47}
48if(!$MTR_COMBINATION_TRX_ID) {
49  select x as ASOF2_x, y from t1 for system_time as of @t0;
50  select x as FROMTO2_x, y from t1 for system_time from '1970-01-01 00:00' to @t1;
51  select x as BETWAND2_x, y from t1 for system_time between timestamp '1970-01-01 00:00' and timestamp @t1;
52}
53
54drop table t1;
55
56replace_result $default_engine ENGINE $sys_datatype_expl SYS_TYPE;
57eval create table t1(
58  x int,
59  y int,
60  sys_start $sys_datatype_expl as row start invisible,
61  sys_end $sys_datatype_expl as row end invisible,
62  period for system_time (sys_start, sys_end))
63with system versioning engine=$default_engine;
64
65create table t2 like t1;
66
67insert into t1 values (1, 1), (1, 2), (1, 3), (4, 4), (5, 5);
68insert into t2 values (1, 2), (2, 1), (3, 1);
69set @t0= now(6);
70
71select 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;
72select 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;
73select 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;
74
75delete from t1;
76delete from t2;
77
78select IJ2_x1,y1,x2,y2 from (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)
79for system_time as of timestamp @t0 as t;
80select LJ2_x1,y1,x2,y2 from (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)
81for system_time as of timestamp @t0 as t;
82select RJ2_x1,y1,x2,y2 from (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)
83for system_time as of timestamp @t0 as t;
84
85drop table t1;
86drop table t2;
87
88--echo # MDEV-14686 Server crashes in Item_field::used_tables on 2nd call of SP [#422]
89create or replace table t1 (called int, bad int) with system versioning;
90create or replace procedure bad() select * from t1 where bad in (select called from t1);
91--disable_query_log
92call bad; call bad; call bad; call bad; call bad; call bad; call bad; call bad;
93drop procedure bad;
94--enable_query_log
95--echo # bad() is good.
96
97--echo # MDEV-14751 Server crashes in TABLE::versioned on 2nd execution of SP [#431]
98create or replace table t1 (called_bad int);
99create or replace table t2 (b int);
100create or replace procedure bad() select * from t1 where ( 5, 6 ) in ( select b, b from t2 ) and called_bad in ( select max(b) from t2 );
101--disable_query_log
102call bad; call bad; call bad; call bad; call bad; call bad; call bad; call bad;
103drop procedure bad;
104--enable_query_log
105--echo # bad() is good.
106
107--echo # MDEV-14786 Server crashes in Item_cond::transform on 2nd execution of SP querying from a view [#436]
108create or replace table t1 (called_bad int) with system versioning;
109create or replace view v1 as select called_bad from t1 where called_bad < 5;
110create or replace procedure bad() select called_bad from v1;
111--disable_query_log
112call bad; call bad; call bad; call bad; call bad; call bad; call bad; call bad;
113drop procedure bad;
114--enable_query_log
115--echo # bad() is good.
116
117--echo # wildcard expansion on hidden fields.
118create or replace table t1(
119  A int
120) with system versioning;
121insert into t1 values(1);
122select * from t1;
123
124create or replace table t1 (x int);
125insert into t1 values (1);
126--error ER_VERS_NOT_VERSIONED
127select * from t1 for system_time all;
128
129create or replace table t1 (x int) with system versioning;
130insert into t1 values (1);
131--error ER_TABLE_NOT_LOCKED_FOR_WRITE
132select * from t1 for system_time as of now() for update;
133
134create or replace table t1 (a int not null auto_increment primary key) with system versioning;
135select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
136
137create or replace table t1 (a int) with system versioning;
138create or replace table t2 (a int) with system versioning;
139insert into t1 values(1);
140insert into t2 values(1);
141create or replace view v1 as select * from t2 inner join t1 using (a);
142select * from v1;
143drop view v1;
144
145create or replace table t1 (a int) with system versioning;
146insert into t1 values (1);
147create view vt1 as select a from t1;
148select * from t1 natural join vt1;
149drop view vt1;
150
151create or replace table t1(x int) with system versioning;
152select * from (t1 as r left join t1 as u using (x)), t1;
153
154# @end should be max
155create or replace table t1 (a int) with system versioning;
156insert into t1 values (1);
157create trigger read_end after update on t1
158  for each row set @end = old.row_end;
159update t1 set a=2;
160--replace_result 18446744073709551615 MAX_RESULT "2038-01-19 03:14:07.999999" MAX_RESULT
161select @end;
162
163create or replace table t1 (a int) with system versioning;
164create or replace table t2 (b int) with system versioning;
165insert into t1 values (1);
166insert into t2 values (2);
167select * from (select * from t1 cross join t2) as tmp;
168select * from (select * from (select * from t1 cross join t2) as tmp1) as tmp2;
169select * from (select * from t1 cross join t2 for system_time as of timestamp ('1970-01-01 00:00')) as tmp;
170
171create or replace table t1(a1 int) with system versioning;
172create or replace table t2(a2 int) with system versioning;
173insert into t1 values(1),(2);
174insert into t2 values(1),(2);
175select * from t1 for system_time all natural left join t2 for system_time all;
176
177# natural join of a view and table
178create or replace table t1(a1 int) with system versioning;
179create or replace table t2(a2 int) with system versioning;
180insert into t1 values(1),(2);
181insert into t2 values(1),(2);
182create or replace view v1 as select a1 from t1;
183
184select * from v1 natural join t2;
185select * from v1 natural left join t2;
186select * from v1 natural right join t2;
187
188create or replace table t1 (a int) with system versioning;
189insert into t1 values (1);
190insert into t1 values (2);
191insert into t1 values (3);
192select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
193
194create or replace table t1 (x int) with system versioning;
195create or replace table t2 (y int) with system versioning;
196insert into t1 values (1), (2), (3);
197delete from t1 where x = 3;
198insert into t2 values (1);
199select * from t1, t2 for system_time all;
200
201--error ER_VERS_NOT_VERSIONED
202select * from (select * from t1 for system_time all, t2 for system_time all) for system_time all as t;
203--error ER_PARSE_ERROR
204select * from (t1 for system_time all join t2 for system_time all) for system_time all;
205
206--echo # MDEV-16043 Assertion thd->Item_change_list::is_empty() failed in mysql_parse upon SELECT from a view reading from a versioned table
207create or replace table t1 (a int) with system versioning;
208create or replace view v1 as select * from t1;
209prepare stmt from "select * from t1 where exp( '20010609211642053929' )";
210--error ER_DATA_OUT_OF_RANGE
211execute stmt;
212select a from v1;
213
214drop view v1;
215drop table t1, t2;
216
217-- source suite/versioning/common_finish.inc
218