1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Timestamp-based versioning for InnoDB [closes #209]

* Removed integer_fields check
* Reworked Vers_parse_info::check_sys_fields()
* Misc renames
* versioned as vers_sys_type_t

* Removed versioned_by_sql(), versioned_by_engine()

versioned() works as before;
versioned(VERS_TIMESTAMP) is versioned_by_sql();
versioned(VERS_TRX_ID) is versioned_by_engine().

* create_tmp_table() fix
* Foreign constraints for timestamp-based
* Range auto-specifier fix
* SQL: 1-row partition rotation fix [fixes #260]
* Fix 'drop system versioning, algorithm=inplace'
This commit is contained in:
Aleksey Midenkov
2017-12-18 19:03:51 +03:00
committed by GitHub
parent d5e37621cf
commit b55a149194
73 changed files with 1178 additions and 836 deletions

View File

@@ -135,42 +135,58 @@ show create table t;
alter table t modify a int with system versioning;
show create table t;
# TODO: move TRX_ID cases to separate test
-- source suite/versioning/common.inc
create or replace table t(
a int
) engine=innodb;
insert into t values(1);
select * from t;
--error ER_VERS_FIELD_WRONG_TYPE
alter table t
add column trx_start timestamp(6) generated always as row start,
add column trx_end timestamp(6) generated always as row end,
add column trx_start timestamp(6) as row start,
add column trx_end timestamp(6) as row end,
add period for system_time(trx_start, trx_end),
add system versioning;
show create table t;
--echo # Issue #211: drop of system columns required before drop system versioning
alter table t drop column trx_start, drop column trx_end;
show create table t;
alter table t drop system versioning;
insert into t values(1);
call verify_vtq;
alter table t
add column trx_start bigint(20) unsigned generated always as row start,
add column trx_end bigint(20) unsigned generated always as row end,
add column trx_start bigint(20) unsigned as row start,
add column trx_end bigint(20) unsigned as row end,
add period for system_time(trx_start, trx_end),
add system versioning;
call verify_vtq;
show create table t;
alter table t drop column trx_start, drop column trx_end;
## FIXME: #413 TRT is not updated on ADD SYSTEM VERSIONING
# alter table t drop column trx_start, drop column trx_end;
# call verify_vtq;
# alter table t drop system versioning, algorithm=copy;
# call verify_vtq;
create or replace table t(
a int
) engine=innodb;
insert into t values (1);
## FIXME END
call verify_vtq;
alter table t drop system versioning, algorithm=copy;
call verify_vtq;
alter table t add system versioning, algorithm=copy;
call verify_vtq;
show create table t;
update t set a= 2;
select * from t for system_time all;
call verify_vtq;
alter table t add column b int, algorithm=copy;
show create table t;
@@ -184,6 +200,9 @@ call verify_vtq;
alter table t drop system versioning, algorithm=inplace;
call verify_vtq;
## FIXME: #414 IB: inplace for VERS_TIMESTAMP versioning
if (0)
{
alter table t add system versioning, algorithm=inplace;
call verify_vtq;
show create table t;
@@ -200,6 +219,9 @@ call verify_vtq;
alter table t drop column b, algorithm=inplace;
show create table t;
select * from t for system_time all;
}
alter table t add system versioning;
## FIXME END
alter table t drop system versioning, algorithm=copy;
show create table t;
@@ -215,28 +237,22 @@ drop table t;
create or replace table t (a int) with system versioning engine=innodb;
insert into t values (1), (2), (3);
delete from t where a<3;
call verify_vtq;
--replace_regex /'0-[- 0-9.:]+'/'...'/
--error ER_DUP_ENTRY
--error ER_DUP_ENTRY, ER_DUP_ENTRY
alter table t add b int not null unique;
--error ER_UNSUPPORTED_EXTENSION
--error ER_UNSUPPORTED_EXTENSION, ER_UNSUPPORTED_EXTENSION
alter table t add b int auto_increment unique;
alter table t add b int auto_increment null unique;
call verify_vtq;
select * from t;
select * from t for system_time all;
insert into t values (4, 0);
select * from t for system_time all;
call verify_vtq;
create or replace table t (a int) with system versioning;
insert into t values (1), (2), (3);
delete from t where a<3;
--replace_regex /'0-[- 0-9.:]+'/'...'/
--error ER_DUP_ENTRY
--error ER_DUP_ENTRY, ER_DUP_ENTRY
alter table t add b int not null unique;
--replace_regex /#sql-[0-9a-f_]*/#sql-temporary/
--error ER_UNSUPPORTED_EXTENSION
--error ER_UNSUPPORTED_EXTENSION, ER_UNSUPPORTED_EXTENSION
alter table t add b int auto_increment unique;
alter table t add b int auto_increment null unique;
select * from t;
@@ -349,7 +365,7 @@ alter table t add system versioning;
--error ER_VERS_ALREADY_VERSIONED
alter table t add system versioning, drop system versioning;
set @@versioning_alter_history=keep;
set @@system_versioning_alter_history=keep;
create or replace table t(x int, y int) with system versioning engine=innodb;
alter table t modify y int without system versioning;
insert into t values(1, 1);

View File

@@ -1,7 +1,11 @@
-- source suite/versioning/common.inc
create table t1(
id int auto_increment primary key)
id int auto_increment primary key,
sys_trx_start bigint unsigned generated always as row start,
sys_trx_end bigint unsigned generated always as row end,
period for system_time (sys_trx_start, sys_trx_end)
)
with system versioning
engine innodb;

View File

@@ -5,13 +5,6 @@
drop table if exists t1;
--enable_warnings
let $non_sys_datatype= `select sys_datatype(non_default_engine())`;
let $non_sys_datatype_uc= `select upper(sys_datatype(non_default_engine()))`;
let $sys_datatype_null= $sys_datatype NULL DEFAULT NULL;
let $sys_datatype_default_null= $sys_datatype DEFAULT NULL;
let $sys_datatype_not_null= $sys_datatype NOT NULL DEFAULT '0000-00-00 00:00:00.000000';
let $non_sys_datatype_null= $non_sys_datatype NULL;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE NULL ''
eval create table t1 (
x1 int unsigned,
@@ -133,52 +126,52 @@ create or replace table t1 (
# columns with/without system versioning
create or replace table t1 (
A1 int with system versioning,
x15 int with system versioning,
B int
);
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t1;
create or replace table t1 (
A2 int with system versioning,
x16 int with system versioning,
B int
) with system versioning;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t1;
create or replace table t1 (
A3 int,
x17 int,
B int without system versioning
);
create or replace table t1 (
A4 int,
x18 int,
B int without system versioning
) with system versioning;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t1;
create or replace table t1 (
A5 int with system versioning,
x19 int with system versioning,
B int without system versioning
);
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t1;
create or replace table t1 (
A6 int with system versioning,
x20 int with system versioning,
B int without system versioning
) with system versioning;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t1;
create or replace table t1 (
A7 int without system versioning
x21 int without system versioning
);
--error ER_VERS_NO_COLS_DEFINED
--error ER_VERS_TABLE_MUST_HAVE_COLUMNS
create or replace table t1 (
A8 int without system versioning
x22 int without system versioning
) with system versioning;
# CREATE TABLE ... LIKE
@@ -193,7 +186,7 @@ create temporary table tt1 like t1;
show create table tt1;
--echo # CREATE TABLE ... SELECT
create or replace table t1 (x int) with system versioning;
create or replace table t1 (x23 int) with system versioning;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
eval create or replace table t0(
y int,
@@ -247,14 +240,14 @@ show create table t3;
select y from t3 where st = @st;
--echo ### 4. system fields not or wrongly selected
create or replace table t3 with system versioning select x from t1;
create or replace table t3 with system versioning select x23 from t1;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE
show create table t3;
select * from t3;
--error ER_MISSING
create or replace table t3 with system versioning select x, sys_trx_start from t1;
create or replace table t3 with system versioning select x23, sys_trx_start from t1;
--error ER_MISSING
create or replace table t3 with system versioning select x, sys_trx_end from t1;
create or replace table t3 with system versioning select x23, sys_trx_end from t1;
--echo # Prepare checking for historical row
delete from t1;
@@ -281,29 +274,34 @@ select st, en from t3 where y = 2 into @st, @en;
select y from t2 for system_time all where st = @st and en = @en;
--echo ## Default engine detection
--replace_result $non_default_engine NON_DEFAULT_ENGINE $non_sys_datatype NON_SYS_DATATYPE
eval create or replace table t1 (a int) with system versioning engine $non_default_engine;
--replace_result $non_default_engine NON_DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
eval create or replace table t1 (x25 int) with system versioning engine $non_default_engine;
create or replace table t2
as select a, sys_trx_start, sys_trx_end from t1 for system_time all;
--replace_result $default_engine DEFAULT_ENGINE $non_sys_datatype NON_SYS_DATATYPE $non_sys_datatype_null NON_SYS_DATATYPE
as select x25, sys_trx_start, sys_trx_end from t1 for system_time all;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE
show create table t2;
create or replace table t2 with system versioning
as select a, sys_trx_start, sys_trx_end from t1;
--replace_result $non_default_engine NON_DEFAULT_ENGINE $non_sys_datatype NON_SYS_DATATYPE
as select x25, sys_trx_start, sys_trx_end from t1;
--replace_result $non_default_engine NON_DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t2;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype_uc SYS_DATATYPE
create or replace table t1 (
x26 int,
st bigint unsigned generated always as row start,
en bigint unsigned generated always as row end,
period for system_time (st, en)
) with system versioning engine innodb;
--error ER_VERS_FIELD_WRONG_TYPE
eval create or replace table t2 with system versioning engine $default_engine
as select a, sys_trx_start, sys_trx_end from t1 for system_time all;
create or replace table t2 with system versioning engine myisam
as select * from t1;
--replace_result $non_default_engine NON_DEFAULT_ENGINE
eval create or replace table t1 (a int, id int) with system versioning engine $non_default_engine;
eval create or replace table t1 (x27 int, id int) with system versioning engine $non_default_engine;
create or replace table t2 (b int, id int);
create or replace table t3 with system versioning
as select t2.b, t1.a, t1.sys_trx_start, t1.sys_trx_end from t2 inner join t1 on t2.id=t1.id;
--replace_result $non_default_engine NON_DEFAULT_ENGINE $non_sys_datatype NON_SYS_DATATYPE $non_sys_datatype_null NON_SYS_DATATYPE
as select t2.b, t1.x27, t1.sys_trx_start, t1.sys_trx_end from t2 inner join t1 on t2.id=t1.id;
--replace_result $non_default_engine NON_DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE
show create table t3;
--echo ## Errors
@@ -316,11 +314,11 @@ create or replace table t (sys_trx_end int);
alter table t with system versioning;
--error ER_WRONG_USAGE
create or replace temporary table t (x int) with system versioning;
create or replace temporary table t (x28 int) with system versioning;
--error ER_VERS_DUPLICATE_ROW_START_END
create or replace table t1 (
x11 int unsigned,
x29 int unsigned,
Sys_start0 timestamp(6) generated always as row start,
Sys_start timestamp(6) generated always as row start,
Sys_end timestamp(6) generated always as row end,
@@ -328,7 +326,7 @@ create or replace table t1 (
) with system versioning;
--echo ## System fields detection
create or replace table t1 (x int) with system versioning;
create or replace table t1 (x30 int) with system versioning;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
eval create or replace table t2 (
y int,
@@ -338,7 +336,7 @@ eval create or replace table t2 (
) with system versioning;
create or replace table t3
as select x, y, sys_trx_start, sys_trx_end, st, en from t1, t2;
as select x30, y, sys_trx_start, sys_trx_end, st, en from t1, t2;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE
show create table t3;
@@ -349,7 +347,7 @@ eval create or replace table t3 (
en $sys_datatype generated always as row end,
period for system_time (st, en)
) with system versioning
as select x, y, sys_trx_start, sys_trx_end, st, en from t1, t2;
as select x30, y, sys_trx_start, sys_trx_end, st, en from t1, t2;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE $sys_datatype_null SYS_DATATYPE $sys_datatype_not_null SYS_DATATYPE $sys_datatype_default_null SYS_DATATYPE
show create table t3;

View File

@@ -1,2 +1 @@
--plugin-load=versioning
--system-versioning-hide=implicit

View File

@@ -30,10 +30,10 @@ insert into emp (emp_id, name, salary, dept_id, mgr) values
(20, "john", 500, 10, 1),
(30, "jane", 750, 10,1 );
select vtq_commit_ts(max(sys_trx_start)) into @ts_1 from emp;
select max(sys_trx_start) into @ts_1 from emp;
update emp set mgr=30 where name ="john";
select vtq_commit_ts(sys_trx_start) into @ts_2 from emp where name="john";
select sys_trx_start into @ts_2 from emp where name="john";
/* All report to 'Bill' */
with recursive

View File

@@ -0,0 +1,8 @@
[timestamp]
default-storage-engine=innodb
[trx_id]
default-storage-engine=innodb
[myisam]
default-storage-engine=myisam

View File

@@ -1,8 +1,8 @@
-- source include/have_innodb.inc
#################
# Test RESTRICT #
#################
--echo #################
--echo # Test RESTRICT #
--echo #################
create table parent(
id int unique key
@@ -34,9 +34,9 @@ select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
drop table child;
drop table parent;
##############################################
# Test when clustered index is a foreign key #
##############################################
--echo ##############################################
--echo # Test when clustered index is a foreign key #
--echo ##############################################
create table parent(
id int(10) unsigned unique key
@@ -56,9 +56,9 @@ delete from parent where id = 1;
drop table child;
drop table parent;
################
# Test CASCADE #
################
--echo ################
--echo # Test CASCADE #
--echo ################
create table parent(
id int unique key
@@ -74,6 +74,12 @@ create table child(
insert into parent values(1);
insert into child values(1);
--echo ## FIXME: #415 update of foreign constraints is disabled
call mtr.add_suppression("foreign key constraints in timestamp-based temporal table");
--error ER_UNSUPPORTED_EXTENSION
delete from parent where id = 1;
delete from child where parent_id = 1;
--echo ## FIXME END
delete from parent where id = 1;
select * from child;
select * from child for system_time all;
@@ -127,6 +133,9 @@ engine innodb;
insert into parent (id) values (3);
insert into child (id, parent_id) values (3, 3);
--echo ## FIXME: #415 update of foreign constraints is disabled
delete from child;
--echo ## FIXME END
delete from parent;
select * from child;
select * from child for system_time all;
@@ -134,9 +143,9 @@ select * from child for system_time all;
drop table child;
drop table parent;
#################
# Test SET NULL #
#################
--echo #################
--echo # Test SET NULL #
--echo #################
create table parent(
id int unique key
@@ -154,6 +163,9 @@ insert into child values(1);
delete from child;
insert into child values(1);
--echo ## FIXME: #415 update of foreign constraints is disabled
delete from child where parent_id = 1;
--echo ## FIXME END
delete from parent where id = 1;
select * from child;
select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
@@ -161,16 +173,21 @@ delete from child;
insert into parent values(1);
insert into child values(1);
## FIXME: #415 update of foreign constraints is disabled
if (0)
{
update parent set id=id+1;
select * from child;
select * from child for system_time from timestamp '1-1-1' to timestamp now(6);
}
## FIXME END
drop table child;
drop table parent;
###########################
# Parent table is foreign #
###########################
--echo ###########################
--echo # Parent table is foreign #
--echo ###########################
create or replace table parent(
id int unique key
@@ -204,10 +221,10 @@ update parent set id=2;
drop table child;
drop table parent;
--echo ###################
--echo # crash on DELETE #
--echo ###################
###################
# crash on DELETE #
###################
create or replace table a (
cola int(10) primary key,
v_cola int(10) as (cola mod 10) virtual

View File

@@ -197,11 +197,14 @@ set global transaction_registry= on;
# virtual columns
create or replace table t1 (
x int,
y int as (x) virtual
y int as (x) virtual,
sys_trx_start bigint unsigned as row start,
sys_trx_end bigint unsigned as row end,
period for system_time (sys_trx_start, sys_trx_end)
) engine=innodb with system versioning;
insert into t1 values (1, null);
update t1 set x= x + 1;
select *, sys_trx_end = 18446744073709551615 as current from t1 for system_time all;
select x, y, sys_trx_end = 18446744073709551615 as current from t1 for system_time all;
create or replace table t1 (i int) with system versioning engine innodb;
insert into t1 values (1),(2);

View File

@@ -0,0 +1,5 @@
[timestamp]
default-storage-engine=innodb
[myisam]
default-storage-engine=myisam

View File

@@ -1 +1,3 @@
--system-versioning-hide=implicit
--system-versioning-alter-history=keep

View File

@@ -1,7 +1,7 @@
-- source include/have_partition.inc
-- source suite/versioning/common.inc
--echo ### check System Versioning and conventional partitioning
--echo # Check conventional partitioning on temporal tables
create table t1 (x int)
with system versioning
@@ -20,14 +20,15 @@ select * from t1 for system_time all;
select * from t1 partition (p0);
select * from t1 partition (p1);
--echo ### Engine change versioned/non-versioned prohibited
--echo # Engine change native <-> non-native versioning prohibited
--replace_result $default_engine DEFAULT_ENGINE
eval create or replace table t1 (i int) engine=$default_engine with system versioning partition by hash(i);
--replace_result $non_default_engine NON_DEFAULT_ENGINE
--error ER_VERS_ALTER_ENGINE_PROHIBITED
eval alter table t1 engine=$non_default_engine;
--echo ### check server-level partitioning
# create errors
--echo # Check server-level partitioning
--echo ## create errors
--error ER_VERS_ENGINE_UNSUPPORTED
create or replace table t1 (x int)
partition by system_time (
@@ -74,7 +75,7 @@ partition by system_time (
partition p0 history,
partition pn current);
# alter table
--echo ## alter table
--error ER_VERS_WRONG_PARTS
alter table t1 add partition (
partition p1 current);
@@ -82,7 +83,7 @@ alter table t1 add partition (
alter table t1 add partition (
partition p1 history);
--replace_result InnoDB ${INNODB_OR_MYISAM} MyISAM ${INNODB_OR_MYISAM} "bigint(20) unsigned" ${SYS_TRX_TYPE} timestamp(6) ${SYS_TRX_TYPE}
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t1;
insert into t1 values (1), (2);
@@ -95,7 +96,15 @@ alter table t1 drop partition p0;
select x from t1;
# insert, delete, update
--echo # Bug #260: incorrect IB partitioning warning
create or replace table t1 (x int)
with system versioning
partition by system_time limit 1 (
partition p0 history,
partition pn current);
alter table t1 change x big int;
--echo ## insert, delete, update
create or replace table t1 (x int)
with system versioning
partition by system_time (
@@ -104,21 +113,19 @@ partition by system_time (
set @now= now(6);
insert into t1 values (1);
set @ts_start= sys_commit_ts('sys_trx_start');
set @ts_end= sys_commit_ts('sys_trx_end');
set @str= concat('select x, ', @ts_start, ' < @now as A, ', @ts_end, ' > @now as B from t1 partition (p0)');
set @str= concat('select x, sys_trx_start < @now as A, sys_trx_end > @now as B from t1 partition (p0)');
prepare select_p0 from @str;
set @str= concat('select x, ', @ts_start, ' > @now as C, ', @ts_end, ' = timestamp\'2038-01-19 03:14:07.999999\' as D from t1 partition (pn)');
set @str= concat('select x, sys_trx_start > @now as C, sys_trx_end = timestamp\'2038-01-19 03:14:07.999999\' as D from t1 partition (pn)');
prepare select_pn from @str;
execute select_p0;
execute select_pn;
# pruning check
--replace_result ALL system "Using where" ""
--echo ## pruning check
--replace_regex /\d/N/ /ALL/system/ /Using where//
explain partitions select * from t1;
set @str= concat('select ', @ts_start, ' from t1 partition (pn) into @ts0');
set @str= concat('select sys_trx_start from t1 partition (pn) into @ts0');
prepare stmt from @str; execute stmt; drop prepare stmt;
set @now= now(6);
@@ -126,7 +133,7 @@ delete from t1;
execute select_p0;
execute select_pn;
set @str= concat('select ', @ts_start, ' from t1 partition (p0) into @ts1');
set @str= concat('select sys_trx_start from t1 partition (p0) into @ts1');
prepare stmt from @str; execute stmt; drop prepare stmt;
select @ts0 = @ts1;
@@ -136,7 +143,7 @@ insert into t1 values (2);
execute select_p0;
execute select_pn;
set @str= concat('select ', @ts_start, ' from t1 partition (pn) into @ts0');
set @str= concat('select sys_trx_start from t1 partition (pn) into @ts0');
prepare stmt from @str; execute stmt; drop prepare stmt;
set @now= now(6);
@@ -147,17 +154,17 @@ execute select_pn;
drop prepare select_p0;
drop prepare select_pn;
set @str= concat('select ', @ts_start, ' from t1 partition (p0) where x = 2 into @ts1');
set @str= concat('select sys_trx_start from t1 partition (p0) where x = 2 into @ts1');
prepare stmt from @str; execute stmt; drop prepare stmt;
set @str= concat('select ', @ts_end, ' from t1 partition (p0) where x = 2 into @ts2');
set @str= concat('select sys_trx_end from t1 partition (p0) where x = 2 into @ts2');
prepare stmt from @str; execute stmt; drop prepare stmt;
set @str= concat('select ', @ts_start, ' from t1 partition (pn) into @ts3');
set @str= concat('select sys_trx_start from t1 partition (pn) into @ts3');
prepare stmt from @str; execute stmt; drop prepare stmt;
select @ts0 = @ts1;
select @ts2 = @ts3;
# rotation by LIMIT
--echo ## rotation by LIMIT
--error ER_PART_WRONG_VALUE
create or replace table t1 (x int)
with system versioning
@@ -168,28 +175,30 @@ partition by system_time limit 0 (
create or replace table t1 (x int)
with system versioning
partition by system_time limit 1 (
partition by system_time limit 2 (
partition p0 history,
partition p1 history,
partition pn current);
--replace_result InnoDB ${INNODB_OR_MYISAM} MyISAM ${INNODB_OR_MYISAM} "bigint(20) unsigned" ${SYS_TRX_TYPE} timestamp(6) ${SYS_TRX_TYPE}
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t1;
--error ER_DROP_PARTITION_NON_EXISTENT
alter table t1 drop partition non_existent;
insert into t1 values (1), (2);
insert into t1 values (1), (2), (3);
select * from t1 partition (pn);
--echo ### warn about partition switching
delete from t1;
select * from t1 partition (p0);
select * from t1 partition (p1);
insert into t1 values (3);
insert into t1 values (4), (5);
--echo ### warn about full partition
delete from t1;
select * from t1 partition (p1);
select * from t1 partition (p1) order by x;
# rotation by INTERVAL
--echo ## rotation by INTERVAL
--error ER_PART_WRONG_VALUE
create or replace table t1 (x int)
with system versioning
@@ -215,20 +224,21 @@ insert into t1 values (4);
delete from t1;
select * from t1 partition (p1);
# Subpartitions
--echo ## Subpartitions
create or replace table t1 (x int)
with system versioning
partition by system_time limit 1
partition by system_time limit 2
subpartition by key (x)
subpartitions 2 (
partition p0 history,
partition p1 history,
partition pn current);
insert into t1 (x) values (1), (2), (3);
insert into t1 (x) values (1), (2), (3), (4), (5);
select * from t1 partition (pnsp0);
select * from t1 partition (pnsp1);
--echo ### warn about partition switching and about full partition
delete from t1;
select * from t1 partition (p0sp0);
select * from t1 partition (p0sp1);
@@ -256,7 +266,6 @@ create or replace table t1 (i int) engine=innodb partition by key(i);
alter table t1 add system versioning;
insert into t1 values();
drop table t1;
-- source suite/versioning/common_finish.inc

View File

@@ -3,9 +3,13 @@
# test_01
create or replace table t1 (
--replace_result $sys_datatype_expl SYS_DATATYPE
eval create or replace table t1 (
x int unsigned,
y int unsigned
y int unsigned,
sys_trx_start $sys_datatype_expl generated always as row start,
sys_trx_end $sys_datatype_expl generated always as row end,
period for system_time (sys_trx_start, sys_trx_end)
) with system versioning;
insert into t1 (x, y) values
@@ -21,7 +25,7 @@ insert into t1 (x, y) values
(9, 109);
set @t0= now(6);
if ($default_engine == 'InnoDB')
if ($MTR_COMBINATION_TRX_ID)
{
--disable_query_log
select sys_trx_start from t1 limit 1 into @x0;
@@ -33,7 +37,7 @@ 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')
if ($MTR_COMBINATION_TRX_ID)
{
--disable_query_log
set @x1= @t1;
@@ -48,13 +52,13 @@ select x as BETWAND_x, y from t1 for system_time between timestamp '0-0-0 0:0:0'
select x as ALL_x, y from t1 for system_time all;
--disable_query_log
if ($default_engine == 'InnoDB')
if ($MTR_COMBINATION_TRX_ID)
{
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')
if ($MTR_COMBINATION_TIMESTAMP)
{
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;
@@ -196,7 +200,13 @@ for system_time all as t;
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;
create or replace table t1 (
x int,
sys_trx_start bigint unsigned generated always as row start,
sys_trx_end bigint unsigned generated always as row end,
period for system_time (sys_trx_start, sys_trx_end)
) with system versioning engine innodb;
insert into t1 values (1);
set @ts= now(6);
delete from t1;
@@ -206,19 +216,21 @@ select sys_trx_start from t1 for system_time all into @trx_start;
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;
select x from t1 for system_time as of timestamp @ts;
select x from t1 for system_time as of timestamp unix_timestamp(@ts);
select x from t1 for system_time as of timestamp @trx_start;
set @ts= timestamp'1-1-1 0:0:0';
--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;
select x from t1 for system_time as of transaction @ts;
select x from t1 for system_time as of transaction unix_timestamp(@ts);
select x 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;
select x from t1 for system_time as of @ts;
select x from t1 for system_time as of unix_timestamp(@ts);
select x from t1 for system_time as of @trx_start;
--echo ### Issue #365, bug 4 (related to #226, optimized fields)
@@ -275,6 +287,6 @@ select * from t1 where t = '00:00:00' and i > 0 and sys_trx_end <> '2012-12-12 0
drop view v1;
drop table t1, t2;
call innodb_verify_vtq(34);
call verify_vtq_dummy(34);
-- source suite/versioning/common_finish.inc

View File

@@ -6,7 +6,6 @@ create procedure test_01()
begin
declare engine varchar(255) default default_engine();
declare sys_type varchar(255) default sys_datatype(default_engine());
declare fields varchar(255) default sys_commit_ts('sys_start');
set @str= concat('
create table t1(
@@ -67,7 +66,6 @@ create or replace procedure test_02()
begin
declare engine varchar(255) default default_engine();
declare sys_type varchar(255) default sys_datatype(default_engine());
declare fields varchar(255) default sys_commit_ts('sys_start');
set @str0= concat('(
x int,
@@ -200,8 +198,6 @@ select * from (t1 for system_time all join t2 for system_time all) for system_ti
drop view v1;
drop table t1, t2;
call innodb_verify_vtq(27);
drop procedure test_01;
drop procedure test_02;

View File

@@ -1 +0,0 @@
--plugin-load=versioning

View File

@@ -23,19 +23,19 @@ select now() into @ts_0;
insert into dept (dept_id, name) values (10, "accounting");
commit;
select vtq_commit_ts(sys_trx_start) into @ts_1 from dept where dept_id=10;
select sys_trx_start into @ts_1 from dept where dept_id=10;
insert into emp (emp_id, name, salary, dept_id) values (1, "bill", 1000, 10);
commit;
select vtq_commit_ts(sys_trx_start) into @ts_2 from emp where name="bill";
select sys_trx_start into @ts_2 from emp where name="bill";
select * from emp;
update emp set salary=2000 where name="bill";
commit;
select vtq_commit_ts(sys_trx_start) into @ts_3 from emp where name="bill";
select sys_trx_start into @ts_3 from emp where name="bill";
select * from emp;
select * from emp for system_time as of timestamp @ts_2;

View File

@@ -10,9 +10,9 @@ begin
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))
sys_trx_start ', sys_type, ' generated always as row start,
sys_trx_end ', sys_type, ' generated always as row end,
period for system_time (sys_trx_start, sys_trx_end))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
@@ -44,7 +44,10 @@ begin
create table t1 (
id bigint primary key,
x int,
y int without system versioning)
y int without system versioning,
sys_trx_start ', sys_type, ' as row start,
sys_trx_end ', sys_type, ' as row end,
period for system_time (sys_trx_start, sys_trx_end))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
@@ -69,8 +72,11 @@ begin
set @str= concat('
create table t1 (
x int,
y int)
with system versioning
y int,
sys_trx_start bigint unsigned as row start,
sys_trx_end bigint unsigned as row end,
period for system_time (sys_trx_start, sys_trx_end)
) with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
@@ -97,7 +103,10 @@ begin
set @str= concat('
create table t1 (
id int primary key auto_increment,
x int)
x int,
sys_trx_start ', sys_type, ' as row start,
sys_trx_end ', sys_type, ' as row end,
period for system_time (sys_trx_start, sys_trx_end))
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
@@ -125,10 +134,10 @@ begin
set @str= concat('
create table t1(
x int unsigned,
sys_end ', sys_type, ' generated always as row end,
sys_start ', sys_type, ' generated always as row start,
sys_trx_end ', sys_type, ' generated always as row end,
sys_trx_start ', sys_type, ' generated always as row start,
y int unsigned,
period for system_time (sys_start, sys_end),
period for system_time (sys_trx_start, sys_trx_end),
primary key(x, y))
with system versioning
engine ', engine);
@@ -153,9 +162,9 @@ begin
set @str= concat('(
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))
sys_trx_start ', sys_type, ' generated always as row start,
sys_trx_end ', sys_type, ' generated always as row end,
period for system_time (sys_trx_start, sys_trx_end))
with system versioning
engine ', engine);
set @str2= concat('create table t1', @str);
@@ -197,9 +206,13 @@ create procedure test_07(
fields varchar(255))
begin
set @str= concat('(
id bigint primary key,
name varchar(128) with system versioning,
salary bigint)
id bigint primary key without system versioning,
name varchar(128),
salary bigint without system versioning,
sys_trx_start ', sys_type, ' as row start,
sys_trx_end ', sys_type, ' as row end,
period for system_time (sys_trx_start, sys_trx_end))
with system versioning
engine ', engine);
set @str2= concat('create table t1', @str);
@@ -227,34 +240,40 @@ begin
end~~
delimiter ;~~
call test_01('timestamp(6)', 'myisam', 'sys_end');
call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
call test_01('timestamp(6)', 'myisam', 'sys_trx_end');
call test_01('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call test_01('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call verify_vtq;
call test_02('timestamp(6)', 'myisam', 'sys_end');
call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
call test_02('timestamp(6)', 'myisam', 'sys_trx_end');
call test_02('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call test_02('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call verify_vtq;
--echo # Multiple UPDATE of same rows in single transaction create historical
--echo # rows only once (applicable to InnoDB only).
call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
--echo # rows only once (applicable to transaction-based only).
call test_03('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call verify_vtq;
call test_04('timestamp(6)', 'myisam', 'sys_end');
call test_04('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
call test_04('timestamp(6)', 'myisam', 'sys_trx_end');
call test_04('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call test_04('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call verify_vtq;
call test_05('timestamp(6)', 'myisam', 'sys_end');
call test_05('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
call test_05('timestamp(6)', 'myisam', 'sys_trx_end');
call test_05('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call test_05('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call verify_vtq;
call test_06('timestamp(6)', 'myisam', 'sys_end');
call test_06('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
call test_06('timestamp(6)', 'myisam', 'sys_trx_end');
call test_06('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call test_06('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call verify_vtq;
call test_07('timestamp(6)', 'myisam', 'sys_end');
call test_07('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_end)');
--echo # Optimized fields
call test_07('timestamp(6)', 'myisam', 'sys_trx_end');
call test_07('timestamp(6)', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call test_07('bigint unsigned', 'innodb', 'vtq_commit_ts(sys_trx_end)');
call verify_vtq;
--echo ### Issue #365, bug 7 (duplicate of historical row)