1
0
mirror of https://github.com/MariaDB/server.git synced 2025-11-30 05:23:50 +03:00
Files
mariadb/mysql-test/suite/versioning/t/create.test
Aleksey Midenkov 27187443ef MDEV-14650 Assertion 0 failed in TABLE::vers_update_fields [fixes #402]
SQL: fixed selecion of handlerton by respecting partitioning
2017-12-14 19:45:11 +03:00

358 lines
14 KiB
Plaintext

--source suite/versioning/engines.inc
--source suite/versioning/common.inc
--disable_warnings
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,
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;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t1;
--echo # Implicit fields test
create or replace table t1 (
x2 int unsigned
) with system versioning;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t1;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
--error ER_VERS_PERIOD_COLUMNS
eval create or replace table t1 (
x3 int unsigned,
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;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
--error ER_VERS_PERIOD_COLUMNS
eval create or replace table t1 (
x4 int unsigned,
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;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
--error ER_VERS_PERIOD_COLUMNS
eval create or replace table t1 (
x5 int unsigned,
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 ER_MISSING
create or replace table t1 (
x6 int unsigned,
period for system_time (Sys_start, Sys_end)
) with system versioning;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
--error ER_MISSING
eval create or replace table t1 (
x7 int unsigned,
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)
);
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
--error ER_VERS_PERIOD_COLUMNS
eval create or replace table t1 (
x8 int unsigned,
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;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
--error ER_MISSING
eval create or replace table t1 (
x9 int unsigned,
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)
);
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
--error ER_MISSING
eval create or replace table t1 (
x10 int unsigned,
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 ER_VERS_FIELD_WRONG_TYPE, ER_VERS_FIELD_WRONG_TYPE
create or replace table t1 (
x11 int unsigned,
Sys_start bigint unsigned generated always as row start,
Sys_end timestamp(6) generated always as row end,
period for system_time (Sys_start, Sys_end)
) with system versioning;
--error ER_VERS_FIELD_WRONG_TYPE, ER_VERS_FIELD_WRONG_TYPE
create or replace table t1 (
x12 int unsigned,
Sys_start timestamp(6) 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;
--error ER_VERS_FIELD_WRONG_TYPE
create or replace table t1 (
x13 int unsigned,
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 ER_VERS_FIELD_WRONG_TYPE
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;
# columns with/without system versioning
create or replace table t1 (
A1 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,
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,
B int without system versioning
);
create or replace table t1 (
A4 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,
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,
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
);
--error ER_VERS_NO_COLS_DEFINED
create or replace table t1 (
A8 int without system versioning
) with system versioning;
# CREATE TABLE ... LIKE
create or replace table t1 (a int) with system versioning;
create table tt1 like t1;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table tt1;
drop table tt1;
create temporary table tt1 like t1;
--echo # Temporary is stripped from versioning
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table tt1;
--echo # CREATE TABLE ... SELECT
create or replace table t1 (x int) with system versioning;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
eval create or replace table t0(
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;
--echo ## For non-versioned table:
--echo ### 1. implicit system fields are not included
create or replace table t2 as select * from t1;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t2;
--echo ### 2. explicit system fields are included
create or replace table t3 as select * from t0;
select * from t0;
--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;
--echo ## 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;
--echo ### 1. implicit system fields are included as implicit
create or replace table t2 with system versioning as select * from t1;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t2;
--echo #### sys_trx_start, sys_trx_end are copied; wildcard not expanded
select * from t2 where sys_trx_start = @sys_trx_start;
--echo ### 2. explicit system fields are included as non-system
create or replace table t3 with system versioning as select * from t0;
--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;
--echo #### st, en are plain fields now
select * from t3 where y > 2;
select y from t3 where st = @st and sys_trx_start > @st;
--echo ### 3. explicit system fields are kept as system
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
eval 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;
--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 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;
--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;
--error ER_MISSING
create or replace table t3 with system versioning select x, sys_trx_end from t1;
--echo # 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;
select en from t0 for system_time all into @en;
--echo ## 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;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
show create table t3;
select * from t3 for system_time all where sys_trx_start = @sys_trx_start and sys_trx_end = @sys_trx_end;
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 t3 where y = 1 into @st, @en;
select y from t2 for system_time all where st = @st and en = @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;
--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;
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
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
show create table t2;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype_uc SYS_DATATYPE
--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;
--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;
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
show create table t3;
--echo ## Errors
create or replace table t (sys_trx_start int);
--error ER_DUP_FIELDNAME
alter table t with system versioning;
create or replace table t (sys_trx_end int);
--error ER_DUP_FIELDNAME
alter table t with system versioning;
--error ER_WRONG_USAGE
create or replace temporary table t (x int) with system versioning;
--error ER_VERS_DUPLICATE_ROW_START_END
create or replace table t1 (
x11 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,
period for system_time (Sys_start, Sys_end)
) with system versioning;
--echo ## System fields detection
create or replace table t1 (x int) with system versioning;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
eval 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;
--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;
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype SYS_DATATYPE
eval 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;
--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;
drop database test;
create database test;