/
delete.result
310 lines (310 loc) · 5.26 KB
/
delete.result
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
set @@session.time_zone='+00:00';
select ifnull(max(trx_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,
trx_id > 0 as A,
commit_id >= trx_id as B,
begin_ts > '1-1-1 0:0:0' as C,
commit_ts > begin_ts as D
from information_schema.innodb_vtq
where trx_id > @start_trx_id;
select ifnull(max(trx_id), 0)
into @start_trx_id
from information_schema.innodb_vtq;
end~~
create or replace procedure test_01(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('
create or replace table t1(
XNo 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(XNo) values(0);
insert into t1(XNo) values(1);
insert into t1(XNo) values(2);
insert into t1(XNo) values(3);
insert into t1(XNo) values(4);
insert into t1(XNo) values(5);
insert into t1(XNo) values(6);
insert into t1(XNo) values(7);
insert into t1(XNo) values(8);
insert into t1(XNo) values(9);
set @str= concat('select XNo, ',
fields, " < '2038-01-19 03:14:07'
from t1 for system_time
between timestamp '0000-0-0 0:0:0'
and timestamp '2038-01-19 04:14:07'");
prepare stmt from @str; execute stmt;
delete from t1 where XNo = 0;
execute stmt;
delete from t1 where XNo = 1;
execute stmt;
delete from t1 where XNo > 5;
create view vt1 as select XNo from t1;
select XNo from vt1;
delete from vt1 where XNo = 3;
select XNo from vt1;
execute stmt; drop prepare stmt;
drop view vt1;
drop table t1;
end~~
create or replace procedure test_02(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
set @str= concat('create or replace table t1 (
x 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);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1(x) values (1);
select sys_start into @sys_start from t1;
delete from t1;
select * from t1;
select x = 1 as A, sys_start = @sys_start as B, sys_end > sys_start as C
from t1 for system_time between timestamp '0-0-0' and timestamp '2038-01-19 04:14:07';
drop table t1;
end~~
create or replace procedure test_03(
sys_type varchar(255),
engine varchar(255),
fields varchar(255))
begin
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(x, y) values (1, 1), (2, 2), (3, 3), (14, 4);
insert into t2(x, y) values (11, 1), (12, 2), (13, 32), (14, 4);
delete t1, t2 from t1 join t2 where t1.y = 3 and t2.y = 32;
select x as t1_x from t1;
select x as t2_x from t2;
delete t1, t2 from t1 join t2 where t1.x = t2.x;
select x as t1_x from t1;
select x as t2_x from t2;
select x as t1_x_all from t1 for system_time between timestamp '0-0-0' and timestamp '2038-01-19 04:14:07';
select x as t2_x_all from t2 for system_time between timestamp '0-0-0' and timestamp '2038-01-19 04:14:07';
drop table t1;
drop table t2;
end~~
# Basic + delete from view
call test_01('timestamp(6)', 'myisam', 'sys_end');
XNo sys_end < '2038-01-19 03:14:07'
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
XNo sys_end < '2038-01-19 03:14:07'
0 1
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
XNo sys_end < '2038-01-19 03:14:07'
0 1
1 1
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
XNo
2
3
4
5
XNo
2
4
5
XNo sys_end < '2038-01-19 03:14:07'
0 1
1 1
2 0
3 1
4 0
5 0
6 1
7 1
8 1
9 1
call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
XNo vtq_commit_ts(sys_end) < '2038-01-19 03:14:07'
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
XNo vtq_commit_ts(sys_end) < '2038-01-19 03:14:07'
0 1
1 0
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
XNo vtq_commit_ts(sys_end) < '2038-01-19 03:14:07'
0 1
1 1
2 0
3 0
4 0
5 0
6 0
7 0
8 0
9 0
XNo
2
3
4
5
XNo
2
4
5
XNo vtq_commit_ts(sys_end) < '2038-01-19 03:14:07'
0 1
1 1
2 0
3 1
4 0
5 0
6 1
7 1
8 1
9 1
call verify_vtq;
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
# Check sys_start, sys_end
call test_02('timestamp(6)', 'myisam', 'sys_end');
x sys_start sys_end
A B C
1 1 1
call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
x sys_start sys_end
A B C
1 1 1
call verify_vtq;
No A B C D
1 1 1 1 1
2 1 1 1 1
# Multi-delete
call test_03('timestamp(6)', 'myisam', 'sys_end');
t1_x
1
2
14
t2_x
11
12
14
t1_x
1
2
t2_x
11
12
t1_x_all
1
2
3
14
t2_x_all
11
12
13
14
call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
t1_x
1
2
14
t2_x
11
12
14
t1_x
1
2
t2_x
11
12
t1_x_all
1
2
3
14
t2_x_all
11
12
13
14
call verify_vtq;
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
drop procedure test_01;
drop procedure test_02;
drop procedure test_03;
drop procedure verify_vtq;