mirror of
https://github.com/MariaDB/server.git
synced 2025-09-02 09:41:40 +03:00
SQL: compare TRX_ID fields against timestamps [closes #231]
This commit is contained in:
@@ -60,21 +60,10 @@ select * from tmp;
|
||||
drop table tmp;
|
||||
end if;
|
||||
end~~
|
||||
create procedure test_01()
|
||||
begin
|
||||
declare engine varchar(255) default default_engine();
|
||||
declare sys_type varchar(255) default sys_datatype();
|
||||
declare fields varchar(255) default sys_commit_ts('sys_start');
|
||||
set @str= concat('
|
||||
create table t1(
|
||||
x int unsigned,
|
||||
y int unsigned,
|
||||
sys_start ', sys_type, ' generated always as row start,
|
||||
sys_end ', sys_type, ' generated always as row end,
|
||||
period for system_time (sys_start, sys_end))
|
||||
with system versioning
|
||||
engine ', engine);
|
||||
prepare stmt from @str; execute stmt; drop prepare stmt;
|
||||
create or replace table t1 (
|
||||
x int unsigned,
|
||||
y int unsigned
|
||||
) with system versioning;
|
||||
insert into t1 (x, y) values
|
||||
(0, 100),
|
||||
(1, 101),
|
||||
@@ -87,74 +76,11 @@ insert into t1 (x, y) values
|
||||
(8, 108),
|
||||
(9, 109);
|
||||
set @t0= now(6);
|
||||
if engine = 'innodb' then
|
||||
select sys_start from t1 limit 1 into @x0;
|
||||
end if;
|
||||
delete from t1 where x = 3;
|
||||
delete from t1 where x > 7;
|
||||
insert into t1(x, y) values(3, 33);
|
||||
select sys_start from t1 where x = 3 and y = 33 into @t1;
|
||||
if engine = 'innodb' then
|
||||
set @x1= @t1;
|
||||
select vtq_commit_ts(@x1) into @t1;
|
||||
end if;
|
||||
select sys_trx_start from t1 where x = 3 and y = 33 into @t1;
|
||||
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 FROMTO_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND_ext_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;
|
||||
if engine = 'innodb' then
|
||||
select x as ASOF2_x, y from t1 for system_time as of transaction @x0;
|
||||
select x as FROMTO2_x, y from t1 for system_time from transaction 0 to transaction @x1;
|
||||
select x as BETWAND2_x, y from t1 for system_time between transaction 0 and transaction @x1;
|
||||
select x as FROMTO2_ext_x, y from t1 for system_time transaction from 0 to @x1;
|
||||
select x as BETWAND2_ext_x, y from t1 for system_time transaction between 0 and @x1;
|
||||
else
|
||||
select x as ASOF2_x, y from t1 for system_time as of timestamp @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;
|
||||
select x as FROMTO2_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
select x as BETWAND2_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
end if;
|
||||
drop table t1;
|
||||
end~~
|
||||
create or replace procedure test_02()
|
||||
begin
|
||||
declare engine varchar(255) default default_engine();
|
||||
declare sys_type varchar(255) default sys_datatype();
|
||||
declare fields varchar(255) default sys_commit_ts('sys_start');
|
||||
set @str0= concat('(
|
||||
x int,
|
||||
y int,
|
||||
sys_start ', sys_type, ' generated always as row start,
|
||||
sys_end ', sys_type, ' generated always as row end,
|
||||
period for system_time (sys_start, sys_end))
|
||||
with system versioning
|
||||
engine ', engine);
|
||||
set @str= concat('create or replace table t1', @str0);
|
||||
prepare stmt from @str; execute stmt; drop prepare stmt;
|
||||
set @str= concat('create or replace table t2', @str0);
|
||||
prepare stmt from @str; execute stmt; drop prepare stmt;
|
||||
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;
|
||||
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
|
||||
system_time as of timestamp @t0;
|
||||
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
|
||||
system_time as of timestamp @t0;
|
||||
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
|
||||
system_time as of timestamp @t0;
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
end~~
|
||||
call test_01();
|
||||
x y
|
||||
0 100
|
||||
1 101
|
||||
@@ -164,6 +90,7 @@ x y
|
||||
6 106
|
||||
7 107
|
||||
3 33
|
||||
select x as ASOF_x, y from t1 for system_time as of timestamp @t0;
|
||||
ASOF_x y
|
||||
0 100
|
||||
1 101
|
||||
@@ -175,6 +102,7 @@ ASOF_x y
|
||||
7 107
|
||||
8 108
|
||||
9 109
|
||||
select x as FROMTO_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
FROMTO_x y
|
||||
0 100
|
||||
1 101
|
||||
@@ -186,6 +114,7 @@ FROMTO_x y
|
||||
7 107
|
||||
8 108
|
||||
9 109
|
||||
select x as BETWAND_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
BETWAND_x y
|
||||
0 100
|
||||
1 101
|
||||
@@ -198,6 +127,7 @@ BETWAND_x y
|
||||
8 108
|
||||
9 109
|
||||
3 33
|
||||
select x as FROMTO_ext_x, y from t1 for system_time from timestamp '0-0-0 0:0:0' to timestamp @t1;
|
||||
FROMTO_ext_x y
|
||||
0 100
|
||||
1 101
|
||||
@@ -209,6 +139,7 @@ FROMTO_ext_x y
|
||||
7 107
|
||||
8 108
|
||||
9 109
|
||||
select x as BETWAND_ext_x, y from t1 for system_time between timestamp '0-0-0 0:0:0' and timestamp @t1;
|
||||
BETWAND_ext_x y
|
||||
0 100
|
||||
1 101
|
||||
@@ -221,6 +152,7 @@ BETWAND_ext_x y
|
||||
8 108
|
||||
9 109
|
||||
3 33
|
||||
select x as ALL_x, y from t1 for system_time all;
|
||||
ALL_x y
|
||||
0 100
|
||||
1 101
|
||||
@@ -290,39 +222,62 @@ BETWAND2_ext_x y
|
||||
8 108
|
||||
9 109
|
||||
3 33
|
||||
call 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;
|
||||
IJ1_x1 y1 x2 y2
|
||||
1 1 1 2
|
||||
1 2 1 2
|
||||
1 3 1 2
|
||||
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;
|
||||
LJ1_x1 y1 x2 y2
|
||||
1 1 1 2
|
||||
1 2 1 2
|
||||
1 3 1 2
|
||||
4 4 NULL NULL
|
||||
5 5 NULL NULL
|
||||
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;
|
||||
RJ1_x1 y1 x2 y2
|
||||
1 1 1 2
|
||||
1 2 1 2
|
||||
1 3 1 2
|
||||
NULL NULL 2 1
|
||||
NULL NULL 3 1
|
||||
delete from t1;
|
||||
delete from t2;
|
||||
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
|
||||
system_time as of timestamp @t0;
|
||||
IJ2_x1 y1 x2 y2
|
||||
1 1 1 2
|
||||
1 2 1 2
|
||||
1 3 1 2
|
||||
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
|
||||
system_time as of timestamp @t0;
|
||||
LJ2_x1 y1 x2 y2
|
||||
1 1 1 2
|
||||
1 2 1 2
|
||||
1 3 1 2
|
||||
4 4 NULL NULL
|
||||
5 5 NULL NULL
|
||||
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
|
||||
system_time as of timestamp @t0;
|
||||
RJ2_x1 y1 x2 y2
|
||||
1 1 1 2
|
||||
1 2 1 2
|
||||
1 3 1 2
|
||||
NULL NULL 2 1
|
||||
NULL NULL 3 1
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
create table t1(
|
||||
A int
|
||||
) with system versioning;
|
||||
@@ -469,8 +424,6 @@ No A B C D
|
||||
25 1 1 1 1
|
||||
26 1 1 1 1
|
||||
27 1 1 1 1
|
||||
drop procedure test_01;
|
||||
drop procedure test_02;
|
||||
drop procedure verify_vtq;
|
||||
drop procedure innodb_verify_vtq;
|
||||
drop function default_engine;
|
||||
|
Reference in New Issue
Block a user