Skip to content

Commit ac5eb97

Browse files
kevgsmidenok
authored andcommitted
SQL: Versioned SHOW CREATE TABLE [closes #125]
1 parent 448374a commit ac5eb97

File tree

10 files changed

+449
-5
lines changed

10 files changed

+449
-5
lines changed

mysql-test/suite/versioning/r/ddl.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ No A B C D
202202
11 1 1 1 1
203203
12 1 1 1 1
204204
drop table t;
205+
drop table t_vtmd;
205206
drop procedure verify_vtq;
206207
drop procedure innodb_verify_vtq;
207208
drop function default_engine;
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
create or replace procedure drop_archives (in vtmd_name varchar(64))
2+
begin
3+
declare archive_name varchar(64);
4+
declare cur_done bool default false;
5+
declare cur cursor for
6+
select cur_tmp.archive_name from cur_tmp;
7+
declare continue handler for not found set cur_done = true;
8+
set @tmp= concat('
9+
create or replace temporary table
10+
cur_tmp as
11+
select vtmd.archive_name from ', vtmd_name, ' as vtmd
12+
for system_time all
13+
where vtmd.archive_name is not null
14+
group by vtmd.archive_name');
15+
prepare stmt from @tmp; execute stmt; drop prepare stmt;
16+
open cur;
17+
fetch_loop: loop
18+
fetch cur into archive_name;
19+
if cur_done then
20+
leave fetch_loop;
21+
end if;
22+
set @tmp= concat('drop table ', archive_name);
23+
prepare stmt from @tmp; execute stmt; drop prepare stmt;
24+
end loop;
25+
drop table cur_tmp;
26+
end~~
27+
create procedure test_01(in engine varchar(64))
28+
begin
29+
set @tmp = concat('create table t (a int) with system versioning engine ', engine);
30+
prepare stmt from @tmp; execute stmt; drop prepare stmt;
31+
set @tm1 = now(6);
32+
alter table t add column b int;
33+
set @tm2 = now(6);
34+
alter table t add column c int;
35+
show create table t for system_time as of timestamp @tm1;
36+
show create table t for system_time as of timestamp @tm2;
37+
show create table t for system_time as of now;
38+
show create table t for system_time as of timestamp now(6);
39+
show create table t;
40+
set @tm3 = now(6);
41+
rename table t to tt;
42+
show create table tt for system_time as of timestamp @tm3;
43+
set @tm4 = now(6);
44+
alter table tt add column d int;
45+
show create table tt for system_time as of timestamp @tm3;
46+
show create table tt for system_time as of timestamp @tm4;
47+
show create table tt;
48+
drop table tt;
49+
call drop_archives('tt_vtmd');
50+
drop table tt_vtmd;
51+
end~~
52+
create table t (a int) with system versioning;
53+
show create table t for system_time as of now;
54+
ERROR 42S02: Table 'test.t_vtmd' doesn't exist
55+
set versioning_ddl_survival=on;
56+
create or replace table t (a int) with system versioning;
57+
show create table t for system_time between timestamp @tm1 and timestamp @tm1;
58+
ERROR HY000: Wrong parameters for `FOR SYSTEM_TIME`: only AS OF allowed here
59+
show create table t for system_time from timestamp @tm1 to timestamp @tm1;
60+
ERROR HY000: Wrong parameters for `FOR SYSTEM_TIME`: only AS OF allowed here
61+
show create table t for system_time before timestamp @tm1;
62+
ERROR HY000: Wrong parameters for `FOR SYSTEM_TIME`: only AS OF allowed here
63+
show create table t for system_time as of timestamp '01-01-1990';
64+
ERROR HY000: VTMD error: failed to query VTMD table
65+
show create table t for system_time as of timestamp '01-01-2020';
66+
ERROR HY000: VTMD error: failed to query VTMD table
67+
drop table t;
68+
call drop_archives('t_vtmd');
69+
drop table t_vtmd;
70+
call test_01('myisam');
71+
Table Create Table
72+
t CREATE TABLE `t` (
73+
`a` int(11) DEFAULT NULL,
74+
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
75+
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
76+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
77+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
78+
Table Create Table
79+
t CREATE TABLE `t` (
80+
`a` int(11) DEFAULT NULL,
81+
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
82+
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
83+
`b` int(11) DEFAULT NULL,
84+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
85+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
86+
Table Create Table
87+
t CREATE TABLE `t` (
88+
`a` int(11) DEFAULT NULL,
89+
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
90+
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
91+
`b` int(11) DEFAULT NULL,
92+
`c` int(11) DEFAULT NULL,
93+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
94+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
95+
Table Create Table
96+
t CREATE TABLE `t` (
97+
`a` int(11) DEFAULT NULL,
98+
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
99+
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
100+
`b` int(11) DEFAULT NULL,
101+
`c` int(11) DEFAULT NULL,
102+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
103+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
104+
Table Create Table
105+
t CREATE TABLE `t` (
106+
`a` int(11) DEFAULT NULL,
107+
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
108+
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
109+
`b` int(11) DEFAULT NULL,
110+
`c` int(11) DEFAULT NULL,
111+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
112+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
113+
Table Create Table
114+
tt CREATE TABLE `tt` (
115+
`a` int(11) DEFAULT NULL,
116+
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
117+
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
118+
`b` int(11) DEFAULT NULL,
119+
`c` int(11) DEFAULT NULL,
120+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
121+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
122+
Table Create Table
123+
tt CREATE TABLE `tt` (
124+
`a` int(11) DEFAULT NULL,
125+
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
126+
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
127+
`b` int(11) DEFAULT NULL,
128+
`c` int(11) DEFAULT NULL,
129+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
130+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
131+
Table Create Table
132+
tt CREATE TABLE `tt` (
133+
`a` int(11) DEFAULT NULL,
134+
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
135+
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
136+
`b` int(11) DEFAULT NULL,
137+
`c` int(11) DEFAULT NULL,
138+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
139+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
140+
Table Create Table
141+
tt CREATE TABLE `tt` (
142+
`a` int(11) DEFAULT NULL,
143+
`sys_trx_start` timestamp(6) GENERATED ALWAYS AS ROW START,
144+
`sys_trx_end` timestamp(6) GENERATED ALWAYS AS ROW END,
145+
`b` int(11) DEFAULT NULL,
146+
`c` int(11) DEFAULT NULL,
147+
`d` int(11) DEFAULT NULL,
148+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
149+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
150+
call test_01('innodb');
151+
Table Create Table
152+
t CREATE TABLE `t` (
153+
`a` int(11) DEFAULT NULL,
154+
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
155+
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
156+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
157+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
158+
Table Create Table
159+
t CREATE TABLE `t` (
160+
`a` int(11) DEFAULT NULL,
161+
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
162+
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
163+
`b` int(11) DEFAULT NULL,
164+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
165+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
166+
Table Create Table
167+
t CREATE TABLE `t` (
168+
`a` int(11) DEFAULT NULL,
169+
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
170+
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
171+
`b` int(11) DEFAULT NULL,
172+
`c` int(11) DEFAULT NULL,
173+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
174+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
175+
Table Create Table
176+
t CREATE TABLE `t` (
177+
`a` int(11) DEFAULT NULL,
178+
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
179+
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
180+
`b` int(11) DEFAULT NULL,
181+
`c` int(11) DEFAULT NULL,
182+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
183+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
184+
Table Create Table
185+
t CREATE TABLE `t` (
186+
`a` int(11) DEFAULT NULL,
187+
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
188+
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
189+
`b` int(11) DEFAULT NULL,
190+
`c` int(11) DEFAULT NULL,
191+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
192+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
193+
Table Create Table
194+
tt CREATE TABLE `tt` (
195+
`a` int(11) DEFAULT NULL,
196+
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
197+
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
198+
`b` int(11) DEFAULT NULL,
199+
`c` int(11) DEFAULT NULL,
200+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
201+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
202+
Table Create Table
203+
tt CREATE TABLE `tt` (
204+
`a` int(11) DEFAULT NULL,
205+
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
206+
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
207+
`b` int(11) DEFAULT NULL,
208+
`c` int(11) DEFAULT NULL,
209+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
210+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
211+
Table Create Table
212+
tt CREATE TABLE `tt` (
213+
`a` int(11) DEFAULT NULL,
214+
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
215+
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
216+
`b` int(11) DEFAULT NULL,
217+
`c` int(11) DEFAULT NULL,
218+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
219+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
220+
Table Create Table
221+
tt CREATE TABLE `tt` (
222+
`a` int(11) DEFAULT NULL,
223+
`sys_trx_start` bigint(20) unsigned GENERATED ALWAYS AS ROW START,
224+
`sys_trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END,
225+
`b` int(11) DEFAULT NULL,
226+
`c` int(11) DEFAULT NULL,
227+
`d` int(11) DEFAULT NULL,
228+
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
229+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
230+
drop procedure test_01;
231+
drop procedure drop_archives;

mysql-test/suite/versioning/t/ddl.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,6 @@ show create table mysql.vtmd_template;
118118

119119
call verify_vtq;
120120
drop table t;
121+
drop table t_vtmd;
121122

122123
-- source suite/versioning/common_finish.inc
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--innodb
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
delimiter ~~;
2+
create or replace procedure drop_archives (in vtmd_name varchar(64))
3+
begin
4+
declare archive_name varchar(64);
5+
declare cur_done bool default false;
6+
declare cur cursor for
7+
select cur_tmp.archive_name from cur_tmp;
8+
declare continue handler for not found set cur_done = true;
9+
10+
set @tmp= concat('
11+
create or replace temporary table
12+
cur_tmp as
13+
select vtmd.archive_name from ', vtmd_name, ' as vtmd
14+
for system_time all
15+
where vtmd.archive_name is not null
16+
group by vtmd.archive_name');
17+
prepare stmt from @tmp; execute stmt; drop prepare stmt;
18+
19+
open cur;
20+
fetch_loop: loop
21+
fetch cur into archive_name;
22+
if cur_done then
23+
leave fetch_loop;
24+
end if;
25+
set @tmp= concat('drop table ', archive_name);
26+
prepare stmt from @tmp; execute stmt; drop prepare stmt;
27+
end loop;
28+
29+
drop table cur_tmp;
30+
end~~
31+
delimiter ;~~
32+
33+
delimiter ~~;
34+
create procedure test_01(in engine varchar(64))
35+
begin
36+
set @tmp = concat('create table t (a int) with system versioning engine ', engine);
37+
prepare stmt from @tmp; execute stmt; drop prepare stmt;
38+
39+
set @tm1 = now(6);
40+
alter table t add column b int;
41+
42+
set @tm2 = now(6);
43+
alter table t add column c int;
44+
45+
show create table t for system_time as of timestamp @tm1;
46+
show create table t for system_time as of timestamp @tm2;
47+
show create table t for system_time as of now;
48+
show create table t for system_time as of timestamp now(6);
49+
show create table t;
50+
51+
set @tm3 = now(6);
52+
rename table t to tt;
53+
show create table tt for system_time as of timestamp @tm3;
54+
55+
set @tm4 = now(6);
56+
alter table tt add column d int;
57+
show create table tt for system_time as of timestamp @tm3;
58+
show create table tt for system_time as of timestamp @tm4;
59+
show create table tt;
60+
61+
drop table tt;
62+
call drop_archives('tt_vtmd');
63+
drop table tt_vtmd;
64+
end~~
65+
delimiter ;~~
66+
67+
create table t (a int) with system versioning;
68+
--error ER_NO_SUCH_TABLE
69+
show create table t for system_time as of now;
70+
71+
set versioning_ddl_survival=on;
72+
73+
create or replace table t (a int) with system versioning;
74+
--error ER_VERS_WRONG_PARAMS
75+
show create table t for system_time between timestamp @tm1 and timestamp @tm1;
76+
--error ER_VERS_WRONG_PARAMS
77+
show create table t for system_time from timestamp @tm1 to timestamp @tm1;
78+
--error ER_VERS_WRONG_PARAMS
79+
show create table t for system_time before timestamp @tm1;
80+
--error ER_VERS_VTMD_ERROR
81+
show create table t for system_time as of timestamp '01-01-1990';
82+
--error ER_VERS_VTMD_ERROR
83+
show create table t for system_time as of timestamp '01-01-2020';
84+
drop table t;
85+
call drop_archives('t_vtmd');
86+
drop table t_vtmd;
87+
88+
call test_01('myisam');
89+
call test_01('innodb');
90+
91+
drop procedure test_01;
92+
drop procedure drop_archives;

0 commit comments

Comments
 (0)