mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
SQL: create..select revisited [closes #370]
This commit is contained in:
@ -3,25 +3,25 @@ create function if not exists non_default_engine()
|
||||
returns varchar(255)
|
||||
deterministic
|
||||
begin
|
||||
if default_engine() = 'innodb' then
|
||||
return 'myisam';
|
||||
if default_engine() = 'InnoDB' then
|
||||
return 'MyISAM';
|
||||
end if;
|
||||
return 'innodb';
|
||||
return 'InnoDB';
|
||||
end~~
|
||||
create table t1 (
|
||||
x1 int unsigned,
|
||||
Sys_start SYS_TRX_TYPE generated always as row start comment 'start',
|
||||
Sys_end SYS_TRX_TYPE generated always as row end comment 'end',
|
||||
Sys_start SYS_DATATYPE generated always as row start comment 'start',
|
||||
Sys_end SYS_DATATYPE generated always as row end comment 'end',
|
||||
period for system_time (Sys_start, Sys_end)
|
||||
) with system versioning;
|
||||
show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`x1` int(10) unsigned DEFAULT NULL,
|
||||
`Sys_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START COMMENT 'start',
|
||||
`Sys_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END COMMENT 'end',
|
||||
`Sys_start` SYS_DATATYPE GENERATED ALWAYS AS ROW START COMMENT 'start',
|
||||
`Sys_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END COMMENT 'end',
|
||||
PERIOD FOR SYSTEM_TIME (`Sys_start`, `Sys_end`)
|
||||
) ENGINE=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
# Implicit fields test
|
||||
create or replace table t1 (
|
||||
x2 int unsigned
|
||||
@ -30,28 +30,28 @@ show create table t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`x2` int(10) unsigned DEFAULT NULL,
|
||||
`sys_trx_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`sys_trx_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
`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=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
create or replace table t1 (
|
||||
x3 int unsigned,
|
||||
Sys_start SYS_TRX_TYPE generated always as row start,
|
||||
Sys_end SYS_TRX_TYPE generated always as row end,
|
||||
Sys_start SYS_DATATYPE generated always as row start,
|
||||
Sys_end SYS_DATATYPE generated always as row end,
|
||||
period for system_time (x, Sys_end)
|
||||
) with system versioning;
|
||||
ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end`
|
||||
create or replace table t1 (
|
||||
x4 int unsigned,
|
||||
Sys_start SYS_TRX_TYPE generated always as row start,
|
||||
Sys_end2 SYS_TRX_TYPE generated always as row end,
|
||||
Sys_start SYS_DATATYPE generated always as row start,
|
||||
Sys_end2 SYS_DATATYPE generated always as row end,
|
||||
period for system_time (Sys_start, Sys_end)
|
||||
) with system versioning;
|
||||
ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end2`
|
||||
create or replace table t1 (
|
||||
x5 int unsigned,
|
||||
Sys_start SYS_TRX_TYPE generated always as row start,
|
||||
Sys_end SYS_TRX_TYPE generated always as row end,
|
||||
Sys_start SYS_DATATYPE generated always as row start,
|
||||
Sys_end SYS_DATATYPE generated always as row end,
|
||||
period for system_time (Sys_start, x)
|
||||
) with system versioning;
|
||||
ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end`
|
||||
@ -62,29 +62,29 @@ period for system_time (Sys_start, Sys_end)
|
||||
ERROR HY000: Wrong parameters for `t1`: missing 'AS ROW START'
|
||||
create or replace table t1 (
|
||||
x7 int unsigned,
|
||||
Sys_start SYS_TRX_TYPE generated always as row start,
|
||||
Sys_end SYS_TRX_TYPE generated always as row end,
|
||||
Sys_start SYS_DATATYPE generated always as row start,
|
||||
Sys_end SYS_DATATYPE generated always as row end,
|
||||
period for system_time (Sys_start, Sys_end)
|
||||
);
|
||||
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
|
||||
create or replace table t1 (
|
||||
x8 int unsigned,
|
||||
Sys_start SYS_TRX_TYPE generated always as row start,
|
||||
Sys_end SYS_TRX_TYPE generated always as row end,
|
||||
Sys_start SYS_DATATYPE generated always as row start,
|
||||
Sys_end SYS_DATATYPE generated always as row end,
|
||||
period for system_time (sys_insert, sys_remove)
|
||||
) with system versioning;
|
||||
ERROR HY000: PERIOD FOR SYSTEM_TIME must use columns `Sys_start` and `Sys_end`
|
||||
create or replace table t1 (
|
||||
x9 int unsigned,
|
||||
Sys_start SYS_TRX_TYPE generated always as row start,
|
||||
Sys_end SYS_TRX_TYPE generated always as row end,
|
||||
Sys_start SYS_DATATYPE generated always as row start,
|
||||
Sys_end SYS_DATATYPE generated always as row end,
|
||||
period for system_time (Sys_start, Sys_end)
|
||||
);
|
||||
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
|
||||
create or replace table t1 (
|
||||
x10 int unsigned,
|
||||
Sys_start SYS_TRX_TYPE generated always as row start,
|
||||
Sys_end SYS_TRX_TYPE generated always as row end,
|
||||
Sys_start SYS_DATATYPE generated always as row start,
|
||||
Sys_end SYS_DATATYPE generated always as row end,
|
||||
period for system_time (Sys_start, Sys_start)
|
||||
);
|
||||
ERROR HY000: Wrong parameters for `t1`: missing 'WITH SYSTEM VERSIONING'
|
||||
@ -125,10 +125,10 @@ Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`A1` int(11) DEFAULT NULL,
|
||||
`B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
|
||||
`sys_trx_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`sys_trx_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
`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=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
create or replace table t1 (
|
||||
A2 int with system versioning,
|
||||
B int
|
||||
@ -138,10 +138,10 @@ Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`A2` int(11) DEFAULT NULL,
|
||||
`B` int(11) DEFAULT NULL,
|
||||
`sys_trx_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`sys_trx_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
`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=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
create or replace table t1 (
|
||||
A3 int,
|
||||
B int without system versioning
|
||||
@ -155,10 +155,10 @@ Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`A4` int(11) DEFAULT NULL,
|
||||
`B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
|
||||
`sys_trx_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`sys_trx_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
`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=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
create or replace table t1 (
|
||||
A5 int with system versioning,
|
||||
B int without system versioning
|
||||
@ -168,10 +168,10 @@ Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`A5` int(11) DEFAULT NULL,
|
||||
`B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
|
||||
`sys_trx_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`sys_trx_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
`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=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
create or replace table t1 (
|
||||
A6 int with system versioning,
|
||||
B int without system versioning
|
||||
@ -181,10 +181,10 @@ Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`A6` int(11) DEFAULT NULL,
|
||||
`B` int(11) DEFAULT NULL WITHOUT SYSTEM VERSIONING,
|
||||
`sys_trx_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`sys_trx_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
`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=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
create or replace table t1 (
|
||||
A7 int without system versioning
|
||||
);
|
||||
@ -198,10 +198,10 @@ show create table tt1;
|
||||
Table Create Table
|
||||
tt1 CREATE TABLE `tt1` (
|
||||
`a` int(11) DEFAULT NULL,
|
||||
`sys_trx_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`sys_trx_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
`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=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
drop table tt1;
|
||||
create temporary table tt1 like t1;
|
||||
Warnings:
|
||||
@ -211,86 +211,176 @@ show create table tt1;
|
||||
Table Create Table
|
||||
tt1 CREATE TEMPORARY TABLE `tt1` (
|
||||
`a` int(11) DEFAULT NULL
|
||||
) ENGINE=INNODB_OR_MYISAM DEFAULT CHARSET=latin1
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1
|
||||
# CREATE TABLE ... SELECT
|
||||
create or replace table t1 (x int) with system versioning;
|
||||
create or replace table t0(
|
||||
y int,
|
||||
st SYS_TRX_TYPE generated always as row start,
|
||||
en SYS_TRX_TYPE generated always as row end,
|
||||
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;
|
||||
## For non-versioned table:
|
||||
### 1. implicit system fields are not included
|
||||
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
|
||||
) ENGINE=INNODB_OR_MYISAM DEFAULT CHARSET=latin1
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1
|
||||
### 2. explicit system fields are included
|
||||
create or replace table t3 as select * from t0;
|
||||
select * from t0;
|
||||
y st en
|
||||
show create table t3;
|
||||
Table Create Table
|
||||
t3 CREATE TABLE `t3` (
|
||||
`y` int(11) DEFAULT NULL
|
||||
) ENGINE=INNODB_OR_MYISAM DEFAULT CHARSET=latin1
|
||||
`y` int(11) DEFAULT NULL,
|
||||
`st` SYS_DATATYPE,
|
||||
`en` SYS_DATATYPE
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1
|
||||
## For versioned table
|
||||
insert into t1 values (1);
|
||||
select sys_trx_start from t1 into @sys_trx_start;
|
||||
insert into t0 values (2);
|
||||
select st from t0 into @st;
|
||||
### 1. implicit system fields are included as implicit
|
||||
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,
|
||||
`sys_trx_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`sys_trx_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
`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=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
select * from t2;
|
||||
) 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
|
||||
1
|
||||
### 2. explicit system fields are included as non-system
|
||||
create or replace table t3 with system versioning as select * from t0;
|
||||
show create table t3;
|
||||
Table Create Table
|
||||
t3 CREATE TABLE `t3` (
|
||||
`y` int(11) DEFAULT NULL,
|
||||
`st` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`en` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
PERIOD FOR SYSTEM_TIME (`st`, `en`)
|
||||
) ENGINE=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
`st` SYS_DATATYPE,
|
||||
`en` SYS_DATATYPE,
|
||||
`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
|
||||
#### st, en are plain fields now
|
||||
select * from t3 where y > 2;
|
||||
y st en
|
||||
select y from t3 where st = @st and sys_trx_start > @st;
|
||||
y
|
||||
2
|
||||
### 3. explicit system fields are kept as system
|
||||
create or replace table t3 (
|
||||
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 * from t0;
|
||||
show create table t3;
|
||||
Table Create Table
|
||||
t3 CREATE TABLE `t3` (
|
||||
`y` int(11) DEFAULT NULL,
|
||||
`st` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
|
||||
`en` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
|
||||
PERIOD FOR SYSTEM_TIME (`st`, `en`)
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
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;
|
||||
show create table t3;
|
||||
Table Create Table
|
||||
t3 CREATE TABLE `t3` (
|
||||
`x` 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
|
||||
1
|
||||
create or replace table t3 with system versioning select x, 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;
|
||||
ERROR HY000: Wrong parameters for `t3`: missing 'AS ROW START'
|
||||
# Prepare checking for historical row
|
||||
delete from t1;
|
||||
select sys_trx_end from t1 for system_time all into @sys_trx_end;
|
||||
delete from t0;
|
||||
create or replace table t1 (x int) with system versioning;
|
||||
select en from t0 for system_time all into @en;
|
||||
## Combinations of versioned + non-versioned
|
||||
create or replace table t2 (y int);
|
||||
insert into t2 values (3);
|
||||
create or replace table t3 with system versioning select * from t1 for system_time all, t2;
|
||||
show create table t3;
|
||||
Table Create Table
|
||||
t3 CREATE TABLE `t3` (
|
||||
`x` int(11) DEFAULT NULL,
|
||||
`sys_trx_start` SYS_TRX_TYPE GENERATED ALWAYS AS ROW START,
|
||||
`sys_trx_end` SYS_TRX_TYPE GENERATED ALWAYS AS ROW END,
|
||||
`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=INNODB_OR_MYISAM DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
create or replace table t2 with system versioning as select * from t0;
|
||||
create or replace table t3 with system versioning select x, y, t1.sys_trx_start, t2.en from t1, t2;
|
||||
ERROR HY000: Wrong parameters for `t3`: system fields selected from different tables
|
||||
) 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
|
||||
1 3
|
||||
create or replace table t2 like t0;
|
||||
insert into t2 values (1), (2);
|
||||
delete from t2 where y = 2;
|
||||
create or replace table t3 select * from t2 for system_time all;
|
||||
select st, en from t2 where y = 1 into @st, @en;
|
||||
select st, en from t3 where y = 1 into @st, @en;
|
||||
select y from t2 for system_time all where st = @st and en = @en;
|
||||
y
|
||||
1
|
||||
select st, en from t2 for system_time all where y = 2 into @st, @en;
|
||||
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;
|
||||
y
|
||||
2
|
||||
create or replace table t1 (a int) with system versioning engine INNODB_OR_MYISAM;
|
||||
create or replace table t2 as select a, sys_trx_start, sys_trx_end from t1 for system_time all;
|
||||
create or replace table t2 with system versioning engine INNODB_OR_MYISAM 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_TRX_TYPE for versioned table `t2`
|
||||
create or replace table t1 (a int, id int) with system versioning engine INNODB_OR_MYISAM;
|
||||
## Default engine detection
|
||||
create or replace table t1 (a 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;
|
||||
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
|
||||
) 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;
|
||||
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,
|
||||
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 t2 (b int, id int);
|
||||
create or replace table t3 as
|
||||
select t2.b, t1.a, t1.sys_trx_start, t1.sys_trx_end from t2 inner join t1 on t2.id=t1.id;
|
||||
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;
|
||||
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,
|
||||
PERIOD FOR SYSTEM_TIME (`sys_trx_start`, `sys_trx_end`)
|
||||
) ENGINE=NON_DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
## Errors
|
||||
create or replace table t (sys_trx_start int);
|
||||
alter table t with system versioning;
|
||||
ERROR 42S21: Duplicate column name 'sys_trx_start'
|
||||
@ -307,5 +397,43 @@ Sys_end timestamp(6) generated always as row end,
|
||||
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 t2 (
|
||||
y int,
|
||||
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;
|
||||
create or replace table t3
|
||||
as select x, 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,
|
||||
`y` int(11) DEFAULT NULL,
|
||||
`sys_trx_start` SYS_DATATYPE,
|
||||
`sys_trx_end` SYS_DATATYPE,
|
||||
`st` SYS_DATATYPE,
|
||||
`en` SYS_DATATYPE
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1
|
||||
create or replace table t3 (
|
||||
y int,
|
||||
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;
|
||||
show create table t3;
|
||||
Table Create Table
|
||||
t3 CREATE TABLE `t3` (
|
||||
`x` int(11) DEFAULT NULL,
|
||||
`y` int(11) DEFAULT NULL,
|
||||
`sys_trx_start` SYS_DATATYPE,
|
||||
`sys_trx_end` SYS_DATATYPE,
|
||||
`st` SYS_DATATYPE GENERATED ALWAYS AS ROW START,
|
||||
`en` SYS_DATATYPE GENERATED ALWAYS AS ROW END,
|
||||
PERIOD FOR SYSTEM_TIME (`st`, `en`)
|
||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
|
||||
drop database test;
|
||||
create database test;
|
||||
|
Reference in New Issue
Block a user