select @@system_versioning_alter_history; create table t( a int ); show create table t; --error ER_VERS_NOT_VERSIONED alter table t drop system versioning; alter table t add system versioning; show create table t; --error ER_VERS_ALTER_NOT_ALLOWED alter table t add column y int; --error ER_VERS_ALTER_ENGINE_PROHIBITED alter table t engine innodb; alter table t drop system versioning; show create table t; set system_versioning_alter_history= keep; --error ER_VERS_FIELD_WRONG_TYPE 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 period for system_time(trx_start, trx_end), add system versioning; --error ER_VERS_FIELD_WRONG_TYPE alter table t add column trx_start timestamp generated always as row start, add column trx_end timestamp generated always as row end, add period for system_time(trx_start, trx_end), add system versioning; --error ER_PARSE_ERROR alter table t add column trx_start timestamp(6) not null generated always as row start, add column trx_end timestamp(6) not null generated always as row end, add period for system_time(trx_start, trx_end), add system versioning; 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 period for system_time(trx_start, trx_end), add system versioning; show create table t; alter table t drop column trx_start, drop column trx_end; alter table t drop system versioning; show create table t; alter table t add system versioning; show create table t; alter table t add column b int; show create table t; alter table t add column c int; show create table t; alter table t add column d int first; show create table t; alter table t add column e int after d; show create table t; alter table t drop column a; show create table t; create or replace table t ( a int, sys_trx_start timestamp(6) generated always as row start, sys_trx_end timestamp(6) generated always as row end, period for system_time(sys_trx_start, sys_trx_end)) with system versioning; select * from t for system_time all; alter table t drop column sys_trx_start; alter table t drop column sys_trx_end; select * from t for system_time all; --error ER_CANT_DROP_FIELD_OR_KEY alter table t drop column sys_trx_start; --error ER_CANT_DROP_FIELD_OR_KEY alter table t drop column sys_trx_end; create or replace table t ( a int, sys_trx_start timestamp(6) generated always as row start, sys_trx_end timestamp(6) generated always as row end, period for system_time(sys_trx_start, sys_trx_end)) with system versioning; select * from t for system_time all; alter table t drop column sys_trx_start, drop column sys_trx_end; select * from t for system_time all; create or replace table t( a int ); insert into t values(1); alter table t add system versioning; show create table t; insert into t values(2); select * from t for system_time all; select * from t; update t set a=3 where a=1; select * from t; select * from t for system_time all; select sys_trx_start from t where a=3 into @tm; alter table t add column b int; select @tm=sys_trx_start from t where a=3; show create table t; select * from t; select * from t for system_time all; alter table t drop system versioning; select * from t; show create table t; --error ER_VERS_NOT_VERSIONED alter table t modify a int with system versioning; --error ER_VERS_NOT_VERSIONED alter table t modify a int without system versioning; alter table t add system versioning; alter table t modify a int without system versioning; 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; alter table t 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 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; ## 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 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; alter table t add column b int, algorithm=copy; show create table t; select * from t; call verify_vtq; alter table t drop column b, algorithm=copy; show create table t; select * from t for system_time all; 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; update t set a= 1; select * from t for system_time all; call verify_vtq; alter table t add column b int, algorithm=inplace; show create table t; select * from t; 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; call verify_vtq; # nullable autoinc test w/o versioning create or replace table t (a int); insert t values (1),(2),(3),(4); alter table t add b int auto_increment null unique; select * from t; 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; --error ER_DUP_ENTRY, ER_DUP_ENTRY alter table t add b int not null unique; --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; select * from t for system_time all; insert into t values (4, 0); select * from t for system_time all; create or replace table t (a int) with system versioning; insert into t values (1), (2), (3); delete from t where a<3; --error ER_DUP_ENTRY, ER_DUP_ENTRY alter table t add b int not null unique; --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; select * from t for system_time all; insert into t values (4, 0); select * from t for system_time all; create or replace table t ( a int, sys_trx_start bigint(20) unsigned generated always as row start, sys_trx_end bigint(20) unsigned generated always as row end, period for system_time(sys_trx_start, sys_trx_end) ) with system versioning engine innodb; --error ER_VERS_ALTER_SYSTEM_FIELD alter table t change column sys_trx_start asdf bigint unsigned; create or replace table t ( a int, sys_trx_start timestamp(6) generated always as row start, sys_trx_end timestamp(6) generated always as row end, period for system_time(sys_trx_start, sys_trx_end) ) with system versioning engine myisam; --error ER_VERS_ALTER_SYSTEM_FIELD alter table t change column sys_trx_start asdf timestamp(6); create or replace table t ( a int, sys_trx_start timestamp(6) generated always as row start, sys_trx_end timestamp(6) generated always as row end, period for system_time(sys_trx_start, sys_trx_end) ) with system versioning; select * from t; --error ER_VERS_SYS_FIELD_NOT_HIDDEN alter table t drop system versioning; alter table t drop column sys_trx_start; select * from t; --error ER_VERS_SYS_FIELD_NOT_HIDDEN alter table t drop system versioning; alter table t drop column sys_trx_end; select * from t; alter table t drop system versioning; show create table t; ## These experimental options are now disabled --error ER_WRONG_VALUE_FOR_VAR set system_versioning_alter_history= SURVIVE; --error ER_WRONG_VALUE_FOR_VAR set system_versioning_alter_history= DROP; if (0) { create or replace table t (a int) with system versioning engine innodb; insert into t values (1); update t set a = 2; select * from t for system_time all; alter table t add column b int; select * from t for system_time all; create or replace table t (a int) with system versioning engine myisam; insert into t values (1); update t set a = 2; select * from t for system_time all; alter table t add column b int; select * from t for system_time all; create or replace table non_empty ( a int, sys_trx_start bigint(20) unsigned, sys_trx_end bigint(20) unsigned ) engine innodb; insert into non_empty values (1, 100, 200); --error ER_VERS_GENERATED_ALWAYS_NOT_EMPTY alter table non_empty change column sys_trx_start sys_trx_start bigint(20) unsigned generated always as row start; --error ER_VERS_GENERATED_ALWAYS_NOT_EMPTY alter table non_empty change column sys_trx_end sys_trx_end bigint(20) unsigned generated always as row end; drop table non_empty; create or replace table t (a int primary key) with system versioning; insert into t values (1); update t set a=2; alter table t drop primary key, add primary key (a), drop system versioning; select * from t; --replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM show create table t; create or replace table t (a int primary key) with system versioning; insert into t values (1); update t set a=2; alter table t drop system versioning; select * from t; --replace_result InnoDB INNODB_OR_MYISAM MyISAM INNODB_OR_MYISAM show create table t; call verify_vtq; } create or replace table t (a int) with system versioning; --error ER_VERS_ALREADY_VERSIONED alter table t add system versioning; --error ER_VERS_ALREADY_VERSIONED alter table t add system versioning, drop system versioning; 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); update t set y=2; drop database test; create database test;