@@ -6,8 +6,8 @@ id int unique key
6
6
) engine innodb;
7
7
create table child(
8
8
parent_id int,
9
- sys_start timestamp(6) as row start invisible,
10
- sys_end timestamp(6) as row end invisible,
9
+ sys_start SYS_DATATYPE as row start invisible,
10
+ sys_end SYS_DATATYPE as row end invisible,
11
11
period for system_time(sys_start, sys_end),
12
12
foreign key(parent_id) references parent(id)
13
13
on delete restrict
@@ -25,7 +25,7 @@ update parent set id=id+1;
25
25
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))
26
26
delete from child;
27
27
update parent set id=id+1;
28
- select * from child for system_time from timestamp 0 to timestamp now(6) ;
28
+ select * from child for system_time all ;
29
29
parent_id
30
30
1
31
31
1
@@ -39,8 +39,8 @@ id int(10) unsigned unique key
39
39
) engine innodb;
40
40
create table child(
41
41
parent_id int(10) unsigned primary key,
42
- sys_start timestamp(6) as row start invisible,
43
- sys_end timestamp(6) as row end invisible,
42
+ sys_start SYS_DATATYPE as row start invisible,
43
+ sys_end SYS_DATATYPE as row end invisible,
44
44
period for system_time(sys_start, sys_end),
45
45
foreign key(parent_id) references parent(id)
46
46
) engine innodb with system versioning;
@@ -58,19 +58,38 @@ id int unique key
58
58
) engine innodb;
59
59
create table child(
60
60
parent_id int,
61
- sys_start timestamp(6) as row start invisible,
62
- sys_end timestamp(6) as row end invisible,
61
+ sys_start SYS_DATATYPE as row start invisible,
62
+ sys_end SYS_DATATYPE as row end invisible,
63
63
period for system_time(sys_start, sys_end),
64
64
foreign key(parent_id) references parent(id)
65
65
on delete cascade
66
66
on update cascade
67
67
) engine innodb with system versioning;
68
- ERROR HY000: CASCADE is not supported for TIMESTAMP(6) AS ROW START/END system-versioned tables
68
+ insert into parent values(1);
69
+ insert into child values(1);
70
+ delete from parent where id = 1;
71
+ select * from child;
72
+ parent_id
73
+ select * from child for system_time all;
74
+ parent_id
75
+ 1
76
+ insert into parent values(1);
77
+ insert into child values(1);
78
+ update parent set id = id + 1;
79
+ select * from child;
80
+ parent_id
81
+ 2
82
+ select * from child for system_time all;
83
+ parent_id
84
+ 1
85
+ 1
86
+ 2
87
+ drop table child;
69
88
drop table parent;
70
89
create or replace table parent (
71
90
id int primary key,
72
- sys_start timestamp(6) as row start invisible,
73
- sys_end timestamp(6) as row end invisible,
91
+ sys_start SYS_DATATYPE as row start invisible,
92
+ sys_end SYS_DATATYPE as row end invisible,
74
93
period for system_time(sys_start, sys_end)
75
94
) with system versioning
76
95
engine innodb;
@@ -97,41 +116,76 @@ engine innodb;
97
116
create or replace table child (
98
117
id int primary key,
99
118
parent_id int not null,
100
- row_start timestamp(6) as row start invisible,
101
- row_end timestamp(6) as row end invisible,
119
+ row_start SYS_DATATYPE as row start invisible,
120
+ row_end SYS_DATATYPE as row end invisible,
102
121
period for system_time(row_start, row_end),
103
122
constraint `parent-fk`
104
123
foreign key (parent_id) references parent (id)
105
124
on delete cascade
106
125
on update restrict
107
126
) with system versioning
108
127
engine innodb;
109
- ERROR HY000: CASCADE is not supported for TIMESTAMP(6) AS ROW START/END system-versioned tables
128
+ insert into parent (id) values (3);
129
+ insert into child (id, parent_id) values (3, 3);
130
+ delete from parent;
131
+ select * from child;
132
+ id parent_id
133
+ select *, check_row(row_start, row_end) from child for system_time all;
134
+ id parent_id check_row(row_start, row_end)
135
+ 3 3 HISTORICAL ROW
136
+ drop table child;
110
137
drop table parent;
111
138
#################
112
139
# Test SET NULL #
113
140
#################
114
- create table parent(
141
+ create or replace table parent(
115
142
id int unique key
116
143
) engine innodb;
117
- create table child(
144
+ create or replace table child(
118
145
parent_id int,
119
- sys_start timestamp(6) as row start invisible,
120
- sys_end timestamp(6) as row end invisible,
146
+ sys_start SYS_DATATYPE as row start invisible,
147
+ sys_end SYS_DATATYPE as row end invisible,
121
148
period for system_time(sys_start, sys_end),
122
149
foreign key(parent_id) references parent(id)
123
150
on delete set null
124
151
on update set null
125
152
) engine innodb with system versioning;
126
- ERROR HY000: SET NULL is not supported for TIMESTAMP(6) AS ROW START/END system-versioned tables
153
+ insert into parent values(1);
154
+ insert into child values(1);
155
+ delete from child;
156
+ insert into child values(1);
157
+ delete from parent where id = 1;
158
+ select * from child;
159
+ parent_id
160
+ NULL
161
+ select *, current_row(sys_end) as current_row from child for system_time all order by sys_end;
162
+ parent_id current_row
163
+ 1 0
164
+ 1 0
165
+ NULL 1
166
+ delete from child;
167
+ insert into parent values(1);
168
+ insert into child values(1);
169
+ update parent set id= id + 1;
170
+ select * from child;
171
+ parent_id
172
+ NULL
173
+ select *, current_row(sys_end) as current_row from child for system_time all order by sys_end;
174
+ parent_id current_row
175
+ 1 0
176
+ 1 0
177
+ NULL 0
178
+ 1 0
179
+ NULL 1
180
+ drop table child;
127
181
drop table parent;
128
182
###########################
129
183
# Parent table is foreign #
130
184
###########################
131
185
create or replace table parent(
132
186
id int unique key,
133
- sys_start timestamp(6) as row start invisible,
134
- sys_end timestamp(6) as row end invisible,
187
+ sys_start SYS_DATATYPE as row start invisible,
188
+ sys_end SYS_DATATYPE as row end invisible,
135
189
period for system_time(sys_start, sys_end)
136
190
) engine innodb with system versioning;
137
191
create or replace table child(
@@ -162,16 +216,16 @@ drop table parent;
162
216
create or replace table a (
163
217
cola int(10) primary key,
164
218
v_cola int(10) as (cola mod 10) virtual,
165
- sys_start timestamp(6) as row start invisible,
166
- sys_end timestamp(6) as row end invisible,
219
+ sys_start SYS_DATATYPE as row start invisible,
220
+ sys_end SYS_DATATYPE as row end invisible,
167
221
period for system_time(sys_start, sys_end)
168
222
) engine=innodb with system versioning;
169
223
create index v_cola on a (v_cola);
170
224
create or replace table b(
171
225
cola int(10),
172
226
v_cola int(10),
173
- sys_start timestamp(6) as row start invisible,
174
- sys_end timestamp(6) as row end invisible,
227
+ sys_start SYS_DATATYPE as row start invisible,
228
+ sys_end SYS_DATATYPE as row end invisible,
175
229
period for system_time(sys_start, sys_end)
176
230
) engine=innodb with system versioning;
177
231
alter table b add constraint `v_cola_fk`
@@ -181,3 +235,58 @@ insert into b(cola, v_cola) values (10,2);
181
235
delete from a;
182
236
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`b`, CONSTRAINT `v_cola_fk` FOREIGN KEY (`v_cola`) REFERENCES `a` (`v_cola`))
183
237
drop table b, a;
238
+ ###############################################
239
+ # CASCADE UPDATE foreign not system versioned #
240
+ ###############################################
241
+ create or replace table parent (
242
+ id smallint unsigned not null auto_increment,
243
+ value int unsigned not null,
244
+ primary key (id, value)
245
+ ) engine = innodb;
246
+ create or replace table child (
247
+ id mediumint unsigned not null auto_increment primary key,
248
+ parent_id smallint unsigned not null,
249
+ parent_value int unsigned not null,
250
+ sys_start SYS_DATATYPE as row start invisible,
251
+ sys_end SYS_DATATYPE as row end invisible,
252
+ period for system_time(sys_start, sys_end),
253
+ constraint `fk_child_parent`
254
+ foreign key (parent_id, parent_value) references parent (id, value)
255
+ on delete cascade
256
+ on update cascade
257
+ ) engine = innodb with system versioning;
258
+ create or replace table subchild (
259
+ id int not null auto_increment primary key,
260
+ parent_id smallint unsigned not null,
261
+ parent_value int unsigned not null,
262
+ constraint `fk_subchild_child_parent`
263
+ foreign key (parent_id, parent_value) references child (parent_id, parent_value)
264
+ on delete cascade
265
+ on update cascade
266
+ ) engine=innodb;
267
+ insert into parent (value) values (23);
268
+ select id, value from parent into @id, @value;
269
+ insert into child values (default, @id, @value);
270
+ insert into subchild values (default, @id, @value);
271
+ select parent_id from subchild;
272
+ parent_id
273
+ 1
274
+ update parent set id = 11, value = value + 1;
275
+ select parent_id from subchild;
276
+ parent_id
277
+ 11
278
+ select * from child;
279
+ id parent_id parent_value
280
+ 1 11 24
281
+ delete from parent;
282
+ select count(*) from child;
283
+ count(*)
284
+ 0
285
+ select * from child for system_time all;
286
+ id parent_id parent_value
287
+ 1 1 23
288
+ 1 11 24
289
+ select count(*) from subchild;
290
+ count(*)
291
+ 0
292
+ drop table subchild, child, parent;
0 commit comments