summaryrefslogtreecommitdiff
path: root/mysql-test/suite/versioning/t/insert.test
blob: 8336e0a2671b45f43592264dafe8b2499686f589 (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
-- source suite/versioning/common.inc

delimiter ~~;
create procedure test_01(
  sys_type varchar(255),
  engine varchar(255),
  fields varchar(255))
begin
  set @str= concat('
  create table t1(
    x int unsigned,
    y int unsigned,
    sys_start ', sys_type, ' as row start invisible,
    sys_end ', sys_type, ' as row end invisible,
    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(3, 4);
  insert delayed into t1(x, y) values(2, 3);
  insert into t1 values(40, 33);
  set @str= concat('select x, y, ', fields, ' from t1');
  prepare stmt from @str; execute stmt; drop prepare stmt;
  drop table t1;
end~~

create procedure test_02(
  sys_type varchar(255),
  engine varchar(255),
  fields varchar(255))
begin
  set @str= concat('
  create table t1(
    id int unsigned auto_increment primary key,
    x int unsigned,
    y int unsigned,
    sys_start ', sys_type, ' as row start invisible,
    sys_end ', sys_type, ' as row end invisible,
    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(33, 44);
  insert into t1(id, x, y) values(20, 33, 44);
  insert into t1 values(40, 33, 44);
  set @str= concat('select id, x, y, ', fields, ' from t1');
  prepare stmt from @str; execute stmt; drop prepare stmt;
  drop table t1;
end~~

create procedure test_03(
  sys_type varchar(255),
  engine varchar(255),
  fields varchar(255))
begin
  set @str= concat('
  create table t1(
    x int unsigned,
    y int unsigned,
    sys_start ', sys_type, ' as row start invisible,
    sys_end ', sys_type, ' as row end invisible,
    period for system_time (sys_start, sys_end))
  with system versioning
  engine ', engine);
  prepare stmt from @str; execute stmt; drop prepare stmt;
  create view vt1_1 as select x, y from t1;
  insert into t1(x, y) values(8001, 9001);
  insert into vt1_1(x, y) values(1001, 2001);
  insert into vt1_1 values(1002, 2002);
  set @str= concat('select x, y, ', fields, ' from t1');
  prepare stmt from @str; execute stmt; drop prepare stmt;
  select x, y from vt1_1;
end~~

create procedure test_04(
  sys_type varchar(255),
  engine varchar(255),
  fields varchar(255))
begin
  set @str= concat('
  create table t1(
    id bigint primary key,
    a int,
    b int)
  with system versioning
  engine ', engine);
  prepare stmt from @str; execute stmt; drop prepare stmt;
  insert into t1 values(1, 1, 1);
  select sys_trx_start, sys_trx_end from t1 into @sys_start, @sys_end;
  select id, a, b from t1;
  insert into t1 values(2, 2, 2);
  select id, a, b, sys_trx_start > @sys_start as C, sys_trx_end = @sys_end as D from t1 where id = 2;
  drop table t1;
end~~

create procedure test_05(
  sys_type varchar(255),
  engine varchar(255),
  fields varchar(255))
begin
  set @str= concat('(
    x int unsigned,
    y int unsigned,
    sys_start ', sys_type, ' as row start invisible,
    sys_end ', sys_type, ' as row end invisible,
    period for system_time (sys_start, sys_end))
  with system versioning
  engine ', engine);
  set @str2= concat('create table t1', @str);
  prepare stmt from @str2; execute stmt; drop prepare stmt;
  set @str2= concat('create table t2', @str);
  prepare stmt from @str2; execute stmt; drop prepare stmt;
  insert into t1(x, y) values
    (1, 1000),
    (2, 2000),
    (3, 3000),
    (4, 4000),
    (5, 5000),
    (6, 6000),
    (7, 7000),
    (8, 8000),
    (9, 9000);
  delete from t1 where x >= 1;
  insert into t1(x, y) values
    (1, 1001),
    (2, 2001),
    (3, 3001),
    (4, 4001),
    (5, 5001),
    (6, 6001);
  insert into t1(x, y, sys_start) values
    (7, 7001, DEFAULT);
  insert into t1(x, y, sys_end) values
    (8, 8001, DEFAULT);
  insert into t1(x, y, sys_start, sys_end) values
    (9, 9001, DEFAULT, DEFAULT);
  insert into t2 select x, y from t1 for system_time between timestamp '0000-0-0 0:0:0' and timestamp '9999-1-1 0:0:0';
  select x, y from t1;
  select x, y from t2;
  drop table t1;
  drop table t2;
end~~
delimiter ;~~

call test_01('timestamp(6)', 'myisam', 'sys_end');
call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');

call test_02('timestamp(6)', 'myisam', 'sys_end');
call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');

call test_03('timestamp(6)', 'myisam', 'sys_end');
drop table t1;
drop view vt1_1;

call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
drop table t1;
drop view vt1_1;

call test_04('timestamp(6)', 'myisam', 'sys_end');
call test_04('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');

call test_05('timestamp(6)', 'myisam', 'sys_end');
call test_05('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');

# VTQ test

call verify_vtq;

create table t1(
  x int unsigned,
  sys_start bigint unsigned 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;

create table t2(x int unsigned) engine=innodb;

start transaction;
insert into t1(x) values(1);
commit;
call verify_vtq;

start transaction;
insert into t2(x) values(1);
savepoint a;
insert into t1(x) values(1);
rollback to a;
commit;
call verify_vtq;

set global system_versioning_transaction_registry= off;
insert into t2(x) values (1);
--error ER_VERS_TRT_IS_DISABLED
insert into t1(x) values (1);
set global system_versioning_transaction_registry= on;

# virtual columns
create or replace table t1 (
  x int,
  y int as (x) virtual,
  sys_trx_start bigint unsigned as row start invisible,
  sys_trx_end bigint unsigned as row end invisible,
  period for system_time (sys_trx_start, sys_trx_end)
) engine=innodb with system versioning;
insert into t1 values (1, null);
update t1 set x= x + 1;
select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all;

create or replace table t1 (i int) with system versioning engine innodb;
insert into t1 values  (1),(2);
--error ER_NONUPDATEABLE_COLUMN
insert into t1 (sys_trx_start) select sys_trx_end from t1;
--error ER_NONUPDATEABLE_COLUMN
insert into t1 (sys_trx_start, sys_trx_end) values (DEFAULT, 1);
insert into t1 (sys_trx_start, sys_trx_end) values (DEFAULT, DEFAULT);

drop table t1;
drop table t2;

drop procedure test_01;
drop procedure test_02;
drop procedure test_03;
drop procedure test_04;
drop procedure test_05;

-- source suite/versioning/common_finish.inc