1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +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

@ -99,90 +99,90 @@ Sys_start bigint generated always as row start,
Sys_end bigint unsigned generated always as row end,
period for system_time (Sys_start, Sys_end)
) with system versioning engine innodb;
ERROR HY000: `Sys_start` must be of type BIGINT(20) UNSIGNED for versioned table `t1`
ERROR HY000: `Sys_start` must be of type TIMESTAMP(6) for temporal table `t1`
create or replace table t1 (
x14 int unsigned,
Sys_start bigint unsigned generated always as row start,
Sys_end bigint generated always as row end,
period for system_time (Sys_start, Sys_end)
) with system versioning engine innodb;
ERROR HY000: `Sys_end` must be of type BIGINT(20) UNSIGNED for versioned table `t1`
ERROR HY000: `Sys_end` must be of type BIGINT(20) UNSIGNED for temporal table `t1`
create or replace table t1 (
A1 int with system versioning,
x15 int with system versioning,
B int
);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A1` int(11) DEFAULT NULL,
`x15` int(11) DEFAULT NULL,
`B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
create or replace table t1 (
A2 int with system versioning,
x16 int with system versioning,
B int
) with system versioning;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A2` int(11) DEFAULT NULL,
`x16` int(11) DEFAULT NULL,
`B` int(11) DEFAULT NULL,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
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;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A4` int(11) DEFAULT NULL,
`x18` int(11) DEFAULT NULL,
`B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
create or replace table t1 (
A5 int with system versioning,
x19 int with system versioning,
B int without system versioning
);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A5` int(11) DEFAULT NULL,
`x19` int(11) DEFAULT NULL,
`B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
create or replace table t1 (
A6 int with system versioning,
x20 int with system versioning,
B int without system versioning
) with system versioning;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`A6` int(11) DEFAULT NULL,
`x20` int(11) DEFAULT NULL,
`B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
create or replace table t1 (
A7 int without system versioning
x21 int without system versioning
);
create or replace table t1 (
A8 int without system versioning
x22 int without system versioning
) with system versioning;
ERROR HY000: Table `t1` has no versioned columns
ERROR HY000: Table `t1` must have at least 1 temporal column
create or replace table t1 (a int) with system versioning;
create table tt1 like t1;
show create table tt1;
@ -204,7 +204,7 @@ tt1 CREATE TEMPORARY TABLE `tt1` (
`a` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1
# CREATE TABLE ... SELECT
create or replace table t1 (x int) with system versioning;
create or replace table t1 (x23 int) with system versioning;
create or replace table t0(
y int,
st SYS_DATATYPE generated always as row start,
@ -217,7 +217,7 @@ create or replace table t2 as select * from t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`x` int(11) DEFAULT NULL
`x23` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1
### 2. explicit system fields are included
create or replace table t3 as select * from t0;
@ -240,14 +240,14 @@ create or replace table t2 with system versioning as select * from t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`x` int(11) DEFAULT NULL,
`x23` int(11) DEFAULT NULL,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
#### sys_trx_start, sys_trx_end are copied; wildcard not expanded
select * from t2 where sys_trx_start = @sys_trx_start;
x
x23
1
### 2. explicit system fields are included as non-system
create or replace table t3 with system versioning as select * from t0;
@ -285,21 +285,21 @@ select y from t3 where st = @st;
y
2
### 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;
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`x` int(11) DEFAULT NULL,
`x23` int(11) DEFAULT NULL,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
select * from t3;
x
x23
1
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 HY000: Wrong parameters for `t3`: missing 'AS ROW END'
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;
ERROR HY000: Wrong parameters for `t3`: missing 'AS ROW START'
# Prepare checking for historical row
delete from t1;
@ -313,14 +313,14 @@ create or replace table t3 with system versioning select * from t1 for system_ti
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`x` int(11) DEFAULT NULL,
`x23` int(11) DEFAULT NULL,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
`y` int(11) DEFAULT NULL,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
select * from t3 for system_time all where sys_trx_start = @sys_trx_start and sys_trx_end = @sys_trx_end;
x y
x23 y
1 3
create or replace table t2 like t0;
insert into t2 values (1), (2);
@ -335,40 +335,46 @@ select y from t2 for system_time all where st = @st and en = @en;
y
2
## Default engine detection
create or replace table t1 (a int) with system versioning engine NON_DEFAULT_ENGINE;
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;
as select x25, sys_trx_start, sys_trx_end from t1 for system_time all;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL,
`sys_trx_start` NON_SYS_DATATYPE DEFAULT NULL,
`sys_trx_end` NON_SYS_DATATYPE DEFAULT NULL
`x25` int(11) DEFAULT NULL,
`sys_trx_start` SYS_DATATYPE,
`sys_trx_end` SYS_DATATYPE
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1
create or replace table t2 with system versioning
as select a, sys_trx_start, sys_trx_end from t1;
as select x25, sys_trx_start, sys_trx_end from t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) DEFAULT NULL,
`sys_trx_start` NON_SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` NON_SYS_DATATYPE GENERATED ALWAYS AS ROW END,
`x25` int(11) DEFAULT NULL,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=NON_DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
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;
ERROR HY000: `sys_trx_start` must be of type SYS_DATATYPE for versioned table `t2`
create or replace table t1 (a int, id int) with system versioning engine NON_DEFAULT_ENGINE;
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;
create or replace table t2 with system versioning engine myisam
as select * from t1;
ERROR HY000: `st` must be of type TIMESTAMP(6) for temporal table `t2`
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;
as select t2.b, t1.x27, t1.sys_trx_start, t1.sys_trx_end from t2 inner join t1 on t2.id=t1.id;
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`b` int(11) DEFAULT NULL,
`a` int(11) DEFAULT NULL,
`sys_trx_start` NON_SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` NON_SYS_DATATYPE GENERATED ALWAYS AS ROW END,
`x27` int(11) DEFAULT NULL,
`sys_trx_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
`sys_trx_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
) ENGINE=NON_DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
## Errors
@ -378,10 +384,10 @@ ERROR 42S21: Duplicate column name 'sys_trx_start'
create or replace table t (sys_trx_end int);
alter table t with system versioning;
ERROR 42S21: Duplicate column name 'sys_trx_end'
create or replace temporary table t (x int) with system versioning;
create or replace temporary table t (x28 int) with system versioning;
ERROR HY000: Incorrect usage of TEMPORARY and WITH SYSTEM VERSIONING
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,
@ -389,7 +395,7 @@ period for system_time (Sys_start, Sys_end)
) with system versioning;
ERROR HY000: Duplicate ROW START column `Sys_start`
## System fields detection
create or replace table t1 (x int) with system versioning;
create or replace table t1 (x30 int) with system versioning;
create or replace table t2 (
y int,
st SYS_DATATYPE generated always as row start,
@ -397,11 +403,11 @@ en SYS_DATATYPE generated always as row end,
period for system_time (st, en)
) 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;
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`x` int(11) DEFAULT NULL,
`x30` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL,
`sys_trx_start` SYS_DATATYPE,
`sys_trx_end` SYS_DATATYPE,
@ -414,11 +420,11 @@ st SYS_DATATYPE generated always as row start,
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;
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`x` int(11) DEFAULT NULL,
`x30` int(11) DEFAULT NULL,
`y` int(11) DEFAULT NULL,
`sys_trx_start` SYS_DATATYPE,
`sys_trx_end` SYS_DATATYPE,