mariadb/mysql-test/suite/versioning/t/select.test
Aleksey Midenkov 4624e565f3 System Versioning 1.0 pre6
Merge remote-tracking branch 'mariadb/bb-10.3-temporal-serg' into trunk
2017-12-15 18:12:18 +03:00

280 lines
9.6 KiB
Text

--source suite/versioning/engines.inc
--source suite/versioning/common.inc
# test_01
create or replace table t1 (
x int unsigned,
y int unsigned
) with system versioning;
insert into t1 (x, y) values
(0, 100),
(1, 101),
(2, 102),
(3, 103),
(4, 104),
(5, 105),
(6, 106),
(7, 107),
(8, 108),
(9, 109);
set @t0= now(6);
if ($default_engine == 'InnoDB')
{
--disable_query_log
select sys_trx_start from t1 limit 1 into @x0;
--enable_query_log
}
delete from t1 where x = 3;
delete from t1 where x > 7;
insert into t1(x, y) values(3, 33);
select sys_trx_start from t1 where x = 3 and y = 33 into @t1;
if ($default_engine == 'InnoDB')
{
--disable_query_log
set @x1= @t1;
select vtq_commit_ts(@x1) into @t1;
--enable_query_log
}
select x, y from t1;
select x as ASOF_x, y from t1 for system_time as of timestamp @t0;
select x as FROMTO_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
select x as BETWAND_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
select x as ALL_x, y from t1 for system_time all;
--disable_query_log
if ($default_engine == 'InnoDB')
{
select x as ASOF2_x, y from t1 for system_time as of @x0;
select x as FROMTO2_x, y from t1 for system_time from @x0 to @x1;
select x as BETWAND2_x, y from t1 for system_time between transaction @x0 and transaction @x1;
}
if ($default_engine != 'InnoDB')
{
select x as ASOF2_x, y from t1 for system_time as of @t0;
select x as FROMTO2_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
select x as BETWAND2_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
}
--enable_query_log
# test_02
create or replace table t1 (
x int unsigned,
y int unsigned
) with system versioning;
create or replace table t2 (
x int unsigned,
y int unsigned
) with system versioning;
insert into t1 values (1, 1), (1, 2), (1, 3), (4, 4), (5, 5);
insert into t2 values (1, 2), (2, 1), (3, 1);
set @t0= now(6);
select t1.x as IJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x;
select t1.x as LJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x;
select t1.x as RJ1_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x;
delete from t1;
delete from t2;
#384
explain extended select * from (select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
explain extended select * from (select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
#383
explain extended select * from (select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
select * from (select t1.x as IJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 inner join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
select * from (select t1.x as LJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 left join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
select * from (select t1.x as RJ2_x1, t1.y as y1, t2.x as x2, t2.y as y2 from t1 right join t2 on t1.x = t2.x)
for system_time as of timestamp @t0 as t;
drop table t1;
drop table t2;
# Wildcard expansion on hidden fields
create table t1(
A int
) with system versioning;
insert into t1 values(1);
select * from t1;
create or replace table t1 (x int);
insert into t1 values (1);
--error ER_VERSIONING_REQUIRED
select * from t1 for system_time all;
create or replace table t1 (x int) with system versioning;
insert into t1 values (1);
--error ER_VERS_HISTORY_LOCK
select * from t1 for system_time all for update;
create or replace table t1 (a int not null auto_increment primary key) with system versioning;
select * from (t1 as t2 left join t1 as t3 using (a)) natural left join t1;
create or replace table t1 (a int) with system versioning;
create or replace table t2 (a int) with system versioning;
insert into t1 values(1);
insert into t2 values(1);
create view v1 as select * from t2 inner join t1 using (a);
select * from v1;
drop view v1;
create or replace table t1 (a int) with system versioning;
insert into t1 values (1);
create view vt1 as select a from t1;
select * from t1 natural join vt1;
drop view vt1;
create or replace table t1(x int) with system versioning;
select * from (t1 as r left join t1 as u using (x)), t1;
# @end should be max
create or replace table t1 (a int) with system versioning;
insert into t1 values (1);
create trigger read_end after update on t1
for each row set @end = old.sys_trx_end;
update t1 set a=2;
--replace_result 18446744073709551615 MAX_RESULT "2038-01-19 03:14:07.999999" MAX_RESULT
select @end;
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);
select * from (select * from t1 cross join t2) as tmp;
select * from (select * from (select * from t1 cross join t2) as tmp1) as tmp2;
select * from (select * from t1 cross join t2 for system_time as of timestamp '0-0-0') as tmp;
create or replace table t1(a1 int) with system versioning;
create or replace table t2(a2 int) with system versioning;
insert into t1 values(1),(2);
insert into t2 values(1),(2);
select * from t1 for system_time all natural left join t2 for system_time all;
# natural join of a view and table
create or replace table t1(a1 int) with system versioning;
create or replace table t2(a2 int) with system versioning;
insert into t1 values(1),(2);
insert into t2 values(1),(2);
create or replace view v1 as select a1 from t1;
select * from v1 natural join t2;
select * from v1 natural left join t2;
select * from v1 natural right join t2;
create or replace table t1 (a int) with system versioning;
insert into t1 values (1);
insert into t1 values (2);
insert into t1 values (3);
select * from t1 left outer join (t1 as t2 left join t1 as t3 using (a)) on t1.a>1;
create or replace table t1 (x int) with system versioning;
create or replace table t2 (y int) with system versioning;
insert into t1 values (1), (2), (3);
delete from t1 where x = 3;
insert into t2 values (1);
select * from t1, t2 for system_time all;
--error ER_VERS_SYSTEM_TIME_CLASH
select * from (select * from t1 for system_time all, t2 for system_time all)
for system_time all as t;
--echo # TRANSACTION/TIMESTAMP specifier in SYSTEM_TIME [MDEV-14645, Issue #396]
create or replace table t1 (x int) with system versioning engine myisam;
--error ER_VERS_ENGINE_UNSUPPORTED
select * from t1 for system_time as of transaction 1;
create or replace table t1 (x int) with system versioning engine innodb;
insert into t1 values (1);
set @ts= now(6);
delete from t1;
select sys_trx_start from t1 for system_time all into @trx_start;
--echo ## ensure @trx_start is much lower than unix timestamp
select @trx_start < unix_timestamp(@ts) - 100 as trx_start_good;
--echo ## TIMESTAMP specifier
select * from t1 for system_time as of timestamp @ts;
select * from t1 for system_time as of timestamp unix_timestamp(@ts);
select * from t1 for system_time as of timestamp @trx_start;
--echo ## TRANSACTION specifier
select * from t1 for system_time as of transaction @ts;
select * from t1 for system_time as of transaction unix_timestamp(@ts);
select * from t1 for system_time as of transaction @trx_start;
--echo ## no specifier (auto-detection)
select * from t1 for system_time as of @ts;
select * from t1 for system_time as of unix_timestamp(@ts);
select * from t1 for system_time as of @trx_start;
--echo ### Issue #365, bug 4 (related to #226, optimized fields)
create or replace table t1 (i int, b int) with system versioning;
insert into t1 values (0, 0), (0, 0);
select min(i) over (partition by b) as f
from (select i + 0 as i, b from t1) as tt
order by i;
--echo ### Issue #365, bug 5 (dangling AND)
create or replace table t1 (a int);
create or replace table t2 (b int) with system versioning;
select * from t1
where exists (select 1 from t2 where t2.b = t1.a and t2.b = t1.a);
--echo ### Issue #365, bug 9 (not a derived subquery)
create or replace table t1 (x int) with system versioning;
select t1.x in (select x from t1) a from t1, (select x from t1) b;
--echo ### Issue #365, bug 10 (WHERE cond freed prematurely for PS)
create or replace table t1 (x int) with system versioning;
insert into t1 values (1);
create or replace view v1 as select x from t1 where x = 1;
prepare stmt from "
select x from t1 where x in (select x from v1);";
execute stmt;
execute stmt;
--echo ### Issue #365, bug 11 (WHERE cond not top level item)
create or replace table t1 (a int, b int, key idx(a)) with system versioning;
insert into t1 values (1, 1), (2, 2);
select * from t1 where (a, 2) in ((1, 1), (2, 2)) and b = 1;
--echo ### Issue #398, NOW is now non-magic
create or replace table t1 (x int) with system versioning;
select * from t1 for system_time as of current_timestamp;
--error ER_BAD_FIELD_ERROR
select * from t1 for system_time as of now;
--echo ### Issue #405, NATURAL JOIN failure
create or replace table t1 (a int) with system versioning;
create or replace table t2 (b int);
create or replace view v1 as select a, sys_trx_start, sys_trx_end from t1 where a > round(rand()*1000);
select * from v1 natural join t2;
--echo ### Issue #406, MDEV-14633 Assertion on TRT read
create or replace table t1 (pk int primary key, i int, t time, key (i)) with system versioning;
insert into t1 values (1, 10, '15:01:53'), (2, 20, '00:00:00');
delete from t1;
--disable_warnings
select * from t1 where t = '00:00:00' and i > 0 and sys_trx_end <> '2012-12-12 00:00:00';
--enable_warnings
drop view v1;
drop table t1, t2;
call innodb_verify_vtq(34);
-- source suite/versioning/common_finish.inc