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
|
--source suite/versioning/engines.inc
--source suite/versioning/common.inc
--source include/have_partition.inc
create or replace table t1 (x int) with system versioning;
insert into t1 values (1);
--disable_cursor_protocol
select now(6) into @t1;
--enable_cursor_protocol
update t1 set x= 2;
--disable_cursor_protocol
select now(6) into @t2;
--enable_cursor_protocol
delete from t1;
set @vt1= concat("create or replace view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'");
prepare stmt from @vt1; execute stmt; drop prepare stmt;
set @vt2= concat("create or replace view vt2 as select *, row_end from t1 for system_time as of timestamp '", @t2, "'");
prepare stmt from @vt2; execute stmt; drop prepare stmt;
select * from t1;
create or replace view vt1 as select * from t1;
--replace_result 18446744073709551615 MAX_RESULT "TIMESTAMP'2038-01-19 03:14:07.999999'" MAX_RESULT
show create view vt1;
drop view vt1;
drop view vt2;
create or replace view vt1 as select * from t1 for system_time all;
select * from vt1;
prepare stmt from 'select * from vt1'; execute stmt; drop prepare stmt;
set @str= concat('create or replace view vt1 as
select * from t1 for system_time as of timestamp "', @t1, '"');
prepare stmt from @str; execute stmt; drop prepare stmt;
select * from t1 for system_time as of timestamp @t1;
select * from vt1;
insert into vt1 values (3);
select * from t1;
select * from vt1;
create or replace table t1 (x int) with system versioning;
insert into t1 values (1), (2);
set @t1=now(6);
delete from t1 where x=2;
set @t2=now(6);
delete from t1 where x=1;
set @t3=now(6);
set @tmp= concat("create or replace view vt1 as select * from t1 for system_time as of timestamp '", @t1, "'");
prepare stmt from @tmp; execute stmt; drop prepare stmt;
select * from vt1;
--echo # VIEW with parameters [tempesta-tech/mariadb#151]
create or replace table t1 (x int) with system versioning;
create or replace view vt1(c) as select x from t1;
--replace_result 18446744073709551615 MAX_RESULT $sys_time_max_replace MAX_RESULT
show create view vt1;
--echo # VIEW over JOIN of versioned tables [tempesta-tech/mariadb#153]
create or replace table t1 (a int) with system versioning;
create or replace table t2 (b int) with system versioning;
insert into t1 values (1);
insert into t2 values (2);
create or replace view vt12 as select * from t1 cross join t2;
select * from vt12;
create or replace view vt12 as select * from t1 for system_time as of timestamp ('1970-01-01 00:00') cross join t2;
select * from vt12;
--echo # VIEW improvements [tempesta-tech/mariadb#183]
create or replace table t3 (x int);
create or replace view vt1 as select * from t1, t2, t3;
--replace_result 18446744073709551615 MAX_RESULT "TIMESTAMP'2038-01-19 03:14:07.999999'" MAX_RESULT
show create view vt1;
create or replace view vt1 as select * from t3, t2, t1;
--replace_result 18446744073709551615 MAX_RESULT "TIMESTAMP'2038-01-19 03:14:07.999999'" MAX_RESULT
show create view vt1;
create or replace view vt1 as select a, t2.row_end as endo from t3, t1, t2;
--replace_result 18446744073709551615 MAX_RESULT "TIMESTAMP'2038-01-19 03:14:07.999999'" MAX_RESULT
show create view vt1;
--echo # VIEW over UNION [tempesta-tech/mariadb#269]
create or replace view vt1 as select * from t1 union select * from t1;
select * from vt1;
--echo # VIEW over UNION with non-versioned [tempesta-tech/mariadb#393]
create or replace table t2 (a int);
create or replace view vt1 as select * from t1 union select * from t2;
select * from vt1;
--echo #
--echo # MDEV-14689 crash on second PS execute
--echo #
create or replace table t1 (a int);
create or replace view v1 as select * from t1;
create or replace table t2 (b int) with system versioning;
prepare stmt from 'select a from v1 inner join t2 group by a order by a';
execute stmt;
execute stmt;
drop view v1;
drop tables t1, t2;
--echo #
--echo # MDEV-15146 SQLError[4122]: View is not system versioned
--echo #
create or replace table t1 (a int) with system versioning;
insert t1 values (1),(2);
set @a=now(6);
create or replace view v1 as select * from t1;
delete from t1;
select * from v1;
select * from v1 for system_time as of @a;
show create view v1;
--echo #
--echo # MDEV-15378 Valid query causes invalid view definition due to syntax limitation in FOR SYSTEM_TIME
--echo #
create or replace table t1 (i int) with system versioning;
select * from t1 for system_time as of now() - interval 6 second;
create or replace view v1 as select * from t1 for system_time as of date_sub(now(), interval 6 second);
show create view v1;
drop view v1, vt1, vt12;
drop tables t1, t3;
--echo #
--echo # MDEV-18727 improve DML operation of System Versioning
--echo #
--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table t1 (
x int,
row_start $sys_datatype_expl as row start invisible,
row_end $sys_datatype_expl as row end invisible,
period for system_time (row_start, row_end)
) with system versioning;
insert into t1 values (1), (2);
create or replace view v1 as select * from t1 where x > 1;
--echo # update, delete
update v1 set x= x + 1;
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
insert v1 values (4);
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
delete from v1 where x < 4;
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
--echo # multi-update
create or replace table t2 like t1;
insert into t2 values (1), (2);
create or replace view v2 as select * from t2 where x > 1;
update v1, v2 set v1.x= v1.x + 1, v2.x= v2.x + 1 where v1.x = v2.x + 2;
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
select *, check_row(row_start, row_end) from t2 for system_time all order by x;
--echo # multi-delete
delete v1, v2 from v1 join v2 where v1.x = v2.x + 2;
select *, check_row(row_start, row_end) from t1 for system_time all order by x;
select *, check_row(row_start, row_end) from t2 for system_time all order by x;
--echo # replace
--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table t1 (
x int primary key, y int,
row_start $sys_datatype_expl as row start invisible,
row_end $sys_datatype_expl as row end invisible,
period for system_time (row_start, row_end)
) with system versioning;
insert into t1 values (1, 0), (2, 0);
create or replace view v1 as select * from t1 where x > 1;
replace v1 values (1, 1);
replace v1 values (2, 1);
replace v1 values (3, 1);
--echo # REPLACE ignores VIEW condition because itself doesn't use WHERE
select *, check_row(row_start, row_end) from t1 for system_time all order by x, row_end;
--echo # insert-select, on duplicate key
insert v1 select * from t1 where x = 1 on duplicate key update x = v1.x - 1;
select *, check_row(row_start, row_end) from t1 for system_time all order by x, row_end;
drop view v1, v2;
drop tables t1, t2;
--echo #
--echo # MDEV-21146 Assertion `m_lock_type == 2' in handler::ha_drop_table upon LOAD DATA
--echo #
create table t1 (a int);
create view v1 as select * from t1;
create or replace table t1 (b int) with system versioning;
--error ER_VIEW_INVALID
load data infile 'xx' into table v1;
# cleanup
drop view v1;
drop table t1;
--echo #
--echo # MDEV-21155 Assertion with versioned table upon DELETE from view of view after replacing first view
--echo #
create table t1 (a int);
insert into t1 values (1);
--replace_result $sys_datatype_expl SYS_DATATYPE
eval create table t2 (
b int,
row_start $sys_datatype_expl as row start invisible,
row_end $sys_datatype_expl as row end invisible,
period for system_time (row_start, row_end)
) with system versioning;
insert into t2 values (2);
create view v1 as select * from t1;
create view v2 as select * from v1;
create or replace view v1 as select * from t2;
delete from v2;
select * from t1;
select *, check_row(row_start, row_end) from t2 for system_time all;
# cleanup
drop view v2;
drop view v1;
drop table t1, t2;
--echo #
--echo # MDEV-23779 Error upon querying the view, that selecting from versioned table with partitions
--echo #
create table t1 (i int) with system versioning
partition by system_time (partition p0 history, partition pn current);
create view v1 as select * from t1 partition (pn);
show create view v1;
# cleanup
drop view v1;
drop table t1;
--source suite/versioning/common_finish.inc
|