|
| 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; |
0 commit comments