Commit c2a70c80 authored by Eugene Kosov's avatar Eugene Kosov Committed by GitHub

SQL, IB: option to drop historical rows on ALTER [closes #249]

parent a6aaa4fe
...@@ -533,6 +533,29 @@ Table Create Table ...@@ -533,6 +533,29 @@ Table Create Table
t CREATE TABLE `t` ( t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL `a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
set versioning_alter_history = DROP;
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;
a
2
1
alter table t add column b int;
select * from t for system_time all;
a b
2 NULL
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;
a
2
1
alter table t add column b int;
select * from t for system_time all;
a b
2 NULL
call verify_vtq; call verify_vtq;
No A B C D No A B C D
1 1 1 1 1 1 1 1 1 1
...@@ -546,6 +569,9 @@ No A B C D ...@@ -546,6 +569,9 @@ No A B C D
9 1 1 1 1 9 1 1 1 1
10 1 1 1 1 10 1 1 1 1
11 1 1 1 1 11 1 1 1 1
12 1 1 1 1
13 1 1 1 1
14 1 1 1 1
drop table t; drop table t;
drop procedure verify_vtq; drop procedure verify_vtq;
drop procedure innodb_verify_vtq; drop procedure innodb_verify_vtq;
......
...@@ -82,7 +82,7 @@ create procedure drop_last_historical(table_name_arg varchar(255)) ...@@ -82,7 +82,7 @@ create procedure drop_last_historical(table_name_arg varchar(255))
begin begin
call concat_exec2('drop table ', get_historical_table_name(table_name_arg)); call concat_exec2('drop table ', get_historical_table_name(table_name_arg));
end~~ end~~
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table t (a int) with system versioning; create or replace table t (a int) with system versioning;
insert into t values (1); insert into t values (1);
update t set a=2 where a=1; update t set a=2 where a=1;
...@@ -106,10 +106,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t') ...@@ -106,10 +106,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t')
@tm=sys_trx_end @tm=sys_trx_end
1 1
call drop_last_historical('t'); call drop_last_historical('t');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table t_vtmd; drop table t_vtmd;
drop table t; drop table t;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table t (a int) with system versioning; create or replace table t (a int) with system versioning;
insert into t values (1); insert into t values (1);
update t set a=2 where a=1; update t set a=2 where a=1;
...@@ -133,10 +133,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t') ...@@ -133,10 +133,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t')
@tm=sys_trx_end @tm=sys_trx_end
1 1
call drop_last_historical('t'); call drop_last_historical('t');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table t_vtmd; drop table t_vtmd;
drop table t; drop table t;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table t (a int) with system versioning engine innodb; create or replace table t (a int) with system versioning engine innodb;
insert into t values (1); insert into t values (1);
update t set a=2 where a=1; update t set a=2 where a=1;
...@@ -160,15 +160,15 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t') ...@@ -160,15 +160,15 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t')
@tm=sys_trx_end @tm=sys_trx_end
1 1
call drop_last_historical('t'); call drop_last_historical('t');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table t_vtmd; drop table t_vtmd;
drop table t; drop table t;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table t (a int) with system versioning engine innodb; create or replace table t (a int) with system versioning engine innodb;
insert into t values (1); insert into t values (1);
update t set a=2 where a=1; update t set a=2 where a=1;
alter table t add column b int, algorithm=inplace; alter table t add column b int, algorithm=inplace;
set versioning_ddl_survival = 0; set versioning_alter_history = keep;
drop procedure concat_exec2; drop procedure concat_exec2;
drop procedure concat_exec3; drop procedure concat_exec3;
drop function get_historical_table_name; drop function get_historical_table_name;
......
...@@ -44,12 +44,12 @@ substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name ...@@ -44,12 +44,12 @@ substr(archive_name, 1, instr(archive_name, '_')) as C_archive_name
from tmp_vtmd for system_time all; from tmp_vtmd for system_time all;
drop table tmp_vtmd; drop table tmp_vtmd;
end~~ end~~
set versioning_ddl_survival= off; set versioning_alter_history= keep;
create or replace table t0 (x int) with system versioning; create or replace table t0 (x int) with system versioning;
show tables; show tables;
Tables_in_test Tables_in_test
t0 t0
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table t0 (x int) with system versioning; create or replace table t0 (x int) with system versioning;
show tables; show tables;
Tables_in_test Tables_in_test
...@@ -72,9 +72,9 @@ call check_vtmd('t0_vtmd'); ...@@ -72,9 +72,9 @@ call check_vtmd('t0_vtmd');
1 1
A_start B_end name C_archive_name A_start B_end name C_archive_name
1 1 t0 NULL 1 1 t0 NULL
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table t0; drop table t0;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table t0 (x int) with system versioning; create or replace table t0 (x int) with system versioning;
ERROR HY000: VTMD error: `test.t0_vtmd` exists and not empty! ERROR HY000: VTMD error: `test.t0_vtmd` exists and not empty!
alter table t0 add column (y int); alter table t0 add column (y int);
...@@ -93,19 +93,19 @@ call check_vtmd('t0_vtmd'); ...@@ -93,19 +93,19 @@ call check_vtmd('t0_vtmd');
A_start B_end name C_archive_name A_start B_end name C_archive_name
1 1 t0 t0_ 1 1 t0 t0_
call drop_archives('t0_vtmd'); call drop_archives('t0_vtmd');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop tables t0, t0_vtmd; drop tables t0, t0_vtmd;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
set versioning_ddl_survival= off; set versioning_alter_history= keep;
create or replace table x0 (x int) with system versioning; create or replace table x0 (x int) with system versioning;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
rename table x0 to d0; rename table x0 to d0;
show tables; show tables;
Tables_in_test Tables_in_test
d0 d0
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table d0; drop table d0;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table x0 (x int) with system versioning; create or replace table x0 (x int) with system versioning;
rename table x0 to d0; rename table x0 to d0;
show tables; show tables;
...@@ -118,9 +118,9 @@ call check_vtmd('d0_vtmd'); ...@@ -118,9 +118,9 @@ call check_vtmd('d0_vtmd');
A_start B_end name C_archive_name A_start B_end name C_archive_name
1 0 x0 NULL 1 0 x0 NULL
1 1 d0 NULL 1 1 d0 NULL
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table d0; drop table d0;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table x0 (x int) with system versioning; create or replace table x0 (x int) with system versioning;
rename table x0 to d0; rename table x0 to d0;
ERROR HY000: VTMD error: `test.d0_vtmd` table already exists! ERROR HY000: VTMD error: `test.d0_vtmd` table already exists!
......
...@@ -52,7 +52,7 @@ end~~ ...@@ -52,7 +52,7 @@ end~~
create table t (a int) with system versioning; create table t (a int) with system versioning;
show create table t for system_time as of now; show create table t for system_time as of now;
ERROR 42S02: Table 'test.t_vtmd' doesn't exist ERROR 42S02: Table 'test.t_vtmd' doesn't exist
set versioning_ddl_survival=on; set versioning_alter_history=survive;
create or replace table t (a int) with system versioning; create or replace table t (a int) with system versioning;
show create table t for system_time between timestamp @tm1 and timestamp @tm1; show create table t for system_time between timestamp @tm1 and timestamp @tm1;
ERROR HY000: SYSTEM_TIME range selector is prohibited ERROR HY000: SYSTEM_TIME range selector is prohibited
......
...@@ -257,6 +257,22 @@ select * from t; ...@@ -257,6 +257,22 @@ select * from t;
alter table t without system versioning; alter table t without system versioning;
show create table t; show create table t;
set versioning_alter_history = DROP;
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;
call verify_vtq; call verify_vtq;
drop table t; drop table t;
......
...@@ -30,7 +30,7 @@ end~~ ...@@ -30,7 +30,7 @@ end~~
delimiter ;~~ delimiter ;~~
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table t (a int) with system versioning; create or replace table t (a int) with system versioning;
insert into t values (1); insert into t values (1);
...@@ -49,10 +49,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t') ...@@ -49,10 +49,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t')
call drop_last_historical('t'); call drop_last_historical('t');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table t_vtmd; drop table t_vtmd;
drop table t; drop table t;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
# same for INNODB ALGORITHM=COPY # same for INNODB ALGORITHM=COPY
create or replace table t (a int) with system versioning; create or replace table t (a int) with system versioning;
...@@ -72,10 +72,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t') ...@@ -72,10 +72,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t')
call drop_last_historical('t'); call drop_last_historical('t');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table t_vtmd; drop table t_vtmd;
drop table t; drop table t;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
# same for INNODB default ALGORITHM # same for INNODB default ALGORITHM
create or replace table t (a int) with system versioning engine innodb; create or replace table t (a int) with system versioning engine innodb;
...@@ -95,10 +95,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t') ...@@ -95,10 +95,10 @@ call concat_exec3('select @tm=sys_trx_end from ', get_historical_table_name('t')
call drop_last_historical('t'); call drop_last_historical('t');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table t_vtmd; drop table t_vtmd;
drop table t; drop table t;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
# no DDL for INNODB explicit ALGORITHM=INPLACE # no DDL for INNODB explicit ALGORITHM=INPLACE
create or replace table t (a int) with system versioning engine innodb; create or replace table t (a int) with system versioning engine innodb;
...@@ -106,7 +106,7 @@ insert into t values (1); ...@@ -106,7 +106,7 @@ insert into t values (1);
update t set a=2 where a=1; update t set a=2 where a=1;
alter table t add column b int, algorithm=inplace; alter table t add column b int, algorithm=inplace;
set versioning_ddl_survival = 0; set versioning_alter_history = keep;
drop procedure concat_exec2; drop procedure concat_exec2;
drop procedure concat_exec3; drop procedure concat_exec3;
......
...@@ -57,18 +57,18 @@ end~~ ...@@ -57,18 +57,18 @@ end~~
delimiter ;~~ delimiter ;~~
# create # create
set versioning_ddl_survival= off; set versioning_alter_history= keep;
create or replace table t0 (x int) with system versioning; create or replace table t0 (x int) with system versioning;
show tables; show tables;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table t0 (x int) with system versioning; create or replace table t0 (x int) with system versioning;
show tables; show tables;
show create table t0_vtmd; show create table t0_vtmd;
call check_vtmd('t0_vtmd'); call check_vtmd('t0_vtmd');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table t0; drop table t0;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
--error ER_VERS_VTMD_ERROR --error ER_VERS_VTMD_ERROR
create or replace table t0 (x int) with system versioning; create or replace table t0 (x int) with system versioning;
...@@ -82,28 +82,28 @@ alter table t0 drop column y; ...@@ -82,28 +82,28 @@ alter table t0 drop column y;
call check_vtmd('t0_vtmd'); call check_vtmd('t0_vtmd');
call drop_archives('t0_vtmd'); call drop_archives('t0_vtmd');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop tables t0, t0_vtmd; drop tables t0, t0_vtmd;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
# rename # rename
set versioning_ddl_survival= off; set versioning_alter_history= keep;
create or replace table x0 (x int) with system versioning; create or replace table x0 (x int) with system versioning;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
rename table x0 to d0; rename table x0 to d0;
show tables; show tables;
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table d0; drop table d0;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table x0 (x int) with system versioning; create or replace table x0 (x int) with system versioning;
rename table x0 to d0; rename table x0 to d0;
show tables; show tables;
call check_vtmd('d0_vtmd'); call check_vtmd('d0_vtmd');
set versioning_ddl_survival= off; set versioning_alter_history= keep;
drop table d0; drop table d0;
set versioning_ddl_survival= on; set versioning_alter_history= survive;
create or replace table x0 (x int) with system versioning; create or replace table x0 (x int) with system versioning;
--error ER_VERS_VTMD_ERROR --error ER_VERS_VTMD_ERROR
......
...@@ -68,7 +68,7 @@ create table t (a int) with system versioning; ...@@ -68,7 +68,7 @@ create table t (a int) with system versioning;
--error ER_NO_SUCH_TABLE --error ER_NO_SUCH_TABLE
show create table t for system_time as of now; show create table t for system_time as of now;
set versioning_ddl_survival=on; set versioning_alter_history=survive;
create or replace table t (a int) with system versioning; create or replace table t (a int) with system versioning;
--error ER_VERS_RANGE_PROHIBITED --error ER_VERS_RANGE_PROHIBITED
......
...@@ -23,7 +23,7 @@ set sql_mode=''; ...@@ -23,7 +23,7 @@ set sql_mode='';
set @orig_storage_engine=@@storage_engine; set @orig_storage_engine=@@storage_engine;
set storage_engine=myisam; set storage_engine=myisam;
set versioning_ddl_survival=off; set versioning_alter_history=keep;
set @have_innodb= (select count(engine) from information_schema.engines where engine='INNODB' and support != 'NO'); set @have_innodb= (select count(engine) from information_schema.engines where engine='INNODB' and support != 'NO');
SET @innodb_or_myisam=IF(@have_innodb <> 0, 'InnoDB', 'MyISAM'); SET @innodb_or_myisam=IF(@have_innodb <> 0, 'InnoDB', 'MyISAM');
......
...@@ -2119,6 +2119,8 @@ class Alter_inplace_info ...@@ -2119,6 +2119,8 @@ class Alter_inplace_info
static const HA_ALTER_FLAGS ALTER_DROP_CHECK_CONSTRAINT= 1ULL << 40; static const HA_ALTER_FLAGS ALTER_DROP_CHECK_CONSTRAINT= 1ULL << 40;
static const HA_ALTER_FLAGS ALTER_DROP_HISTORICAL = 1ULL << 41;
/** /**
Create options (like MAX_ROWS) for the new version of table. Create options (like MAX_ROWS) for the new version of table.
......
...@@ -208,6 +208,13 @@ enum vers_hide_enum ...@@ -208,6 +208,13 @@ enum vers_hide_enum
VERS_HIDE_FULL, VERS_HIDE_FULL,
VERS_HIDE_NEVER VERS_HIDE_NEVER
}; };
enum vers_alter_history_enum
{
VERS_ALTER_HISTORY_KEEP,
VERS_ALTER_HISTORY_SURVIVE,
VERS_ALTER_HISTORY_DROP
};
/* System Versioning end */ /* System Versioning end */
extern char *mysql_home_ptr, *pidfile_name_ptr; extern char *mysql_home_ptr, *pidfile_name_ptr;
......
...@@ -711,7 +711,7 @@ typedef struct system_variables ...@@ -711,7 +711,7 @@ typedef struct system_variables
my_bool vers_force; my_bool vers_force;
ulong vers_hide; ulong vers_hide;
my_bool vers_innodb_algorithm_simple; my_bool vers_innodb_algorithm_simple;
my_bool vers_ddl_survival; ulong vers_alter_history;
} SV; } SV;
/** /**
......
...@@ -300,7 +300,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name, ...@@ -300,7 +300,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
(void) rename_table_in_stat_tables(thd, &db_name, &table_name, (void) rename_table_in_stat_tables(thd, &db_name, &table_name,
&new_db_name, &new_table); &new_db_name, &new_table);
VTMD_rename vtmd(*ren_table); VTMD_rename vtmd(*ren_table);
if (thd->variables.vers_ddl_survival) if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE)
{ {
rc= vtmd.try_rename(thd, new_db_name, new_table); rc= vtmd.try_rename(thd, new_db_name, new_table);
if (rc) if (rc)
...@@ -313,7 +313,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name, ...@@ -313,7 +313,7 @@ do_rename(THD *thd, TABLE_LIST *ren_table, char *new_db, char *new_table_name,
new_alias); new_alias);
if (rc) if (rc)
{ {
if (thd->variables.vers_ddl_survival) if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE)
vtmd.revert_rename(thd, new_db_name); vtmd.revert_rename(thd, new_db_name);
revert_table_name: revert_table_name:
/* /*
......
...@@ -2477,7 +2477,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists, ...@@ -2477,7 +2477,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
*(end= path + path_length - reg_ext_length)= '\0'; *(end= path + path_length - reg_ext_length)= '\0';
if (thd->lex->sql_command == SQLCOM_DROP_TABLE && if (thd->lex->sql_command == SQLCOM_DROP_TABLE &&
thd->variables.vers_ddl_survival && thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE &&
table_type && table_type != view_pseudo_hton) table_type && table_type != view_pseudo_hton)
{ {
error= vtmd.check_exists(thd); error= vtmd.check_exists(thd);
...@@ -5075,7 +5075,8 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table, ...@@ -5075,7 +5075,8 @@ bool mysql_create_table(THD *thd, TABLE_LIST *create_table,
} }
} }
if (create_info->versioned() && thd->variables.vers_ddl_survival) if (create_info->versioned() &&
thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE)
{ {
VTMD_table vtmd(*create_table); VTMD_table vtmd(*create_table);
if (vtmd.update(thd)) if (vtmd.update(thd))
...@@ -6372,6 +6373,8 @@ static bool fill_alter_inplace_info(THD *thd, ...@@ -6372,6 +6373,8 @@ static bool fill_alter_inplace_info(THD *thd,
ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_ADD_CHECK_CONSTRAINT; ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_ADD_CHECK_CONSTRAINT;
if (alter_info->flags & Alter_info::ALTER_DROP_CHECK_CONSTRAINT) if (alter_info->flags & Alter_info::ALTER_DROP_CHECK_CONSTRAINT)
ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_DROP_CHECK_CONSTRAINT; ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_DROP_CHECK_CONSTRAINT;
if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_DROP)
ha_alter_info->handler_flags|= Alter_inplace_info::ALTER_DROP_HISTORICAL;
/* /*
If we altering table with old VARCHAR fields we will be automatically If we altering table with old VARCHAR fields we will be automatically
...@@ -8561,8 +8564,11 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list, ...@@ -8561,8 +8564,11 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list,
else else
{ {
VTMD_rename vtmd(*table_list); VTMD_rename vtmd(*table_list);
if (thd->variables.vers_ddl_survival && vtmd.try_rename(thd, new_db_name, new_table_name)) if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE &&
vtmd.try_rename(thd, new_db_name, new_table_name))
{
goto revert_table_name; goto revert_table_name;
}
else if (Table_triggers_list::change_table_name(thd, else if (Table_triggers_list::change_table_name(thd,
alter_ctx->db, alter_ctx->db,
alter_ctx->alias, alter_ctx->alias,
...@@ -8570,7 +8576,7 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list, ...@@ -8570,7 +8576,7 @@ simple_rename_or_index_change(THD *thd, TABLE_LIST *table_list,
alter_ctx->new_db, alter_ctx->new_db,
alter_ctx->new_alias)) alter_ctx->new_alias))
{ {
if (thd->variables.vers_ddl_survival) if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE)
vtmd.revert_rename(thd, new_db_name); vtmd.revert_rename(thd, new_db_name);
revert_table_name: revert_table_name:
(void) mysql_rename_table(old_db_type, (void) mysql_rename_table(old_db_type,
...@@ -8711,7 +8717,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -8711,7 +8717,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
thd->open_options&= ~HA_OPEN_FOR_ALTER; thd->open_options&= ~HA_OPEN_FOR_ALTER;
bool versioned= table_list->table && table_list->table->versioned(); bool versioned= table_list->table && table_list->table->versioned();
bool vers_data_mod= versioned && bool vers_data_mod= versioned &&
thd->variables.vers_ddl_survival && thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE &&
alter_info->vers_data_modifying(); alter_info->vers_data_modifying();
if (vers_data_mod) if (vers_data_mod)
...@@ -9949,11 +9955,14 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, ...@@ -9949,11 +9955,14 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
else if (keep_versioned) else if (keep_versioned)
{ {
to->file->vers_auto_decrement= 0xffffffffffffffff; to->file->vers_auto_decrement= 0xffffffffffffffff;
if (thd->variables.vers_ddl_survival) if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE)
{ {
query_start= thd->query_start_TIME(); query_start= thd->query_start_TIME();
from_sys_trx_end= from->vers_end_field(); from_sys_trx_end= from->vers_end_field();
to_sys_trx_start= to->vers_start_field(); to_sys_trx_start= to->vers_start_field();
} else if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_DROP)
{
from_sys_trx_end= from->vers_end_field();
} }
} }
...@@ -10011,6 +10020,12 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, ...@@ -10011,6 +10020,12 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
copy_ptr->do_copy(copy_ptr); copy_ptr->do_copy(copy_ptr);
} }
if (thd->variables.vers_alter_history == VERS_ALTER_HISTORY_DROP &&
from_sys_trx_end && !from_sys_trx_end->is_max())
{
continue;
}
if (make_versioned) if (make_versioned)
{ {
to_sys_trx_start->set_notnull(); to_sys_trx_start->set_notnull();
...@@ -10022,7 +10037,8 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, ...@@ -10022,7 +10037,8 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if (!from_sys_trx_end->is_max()) if (!from_sys_trx_end->is_max())
continue; // Drop history rows. continue; // Drop history rows.
} }
else if (keep_versioned && thd->variables.vers_ddl_survival) else if (keep_versioned &&
thd->variables.vers_alter_history == VERS_ALTER_HISTORY_SURVIVE)
{ {
if (!from_sys_trx_end->is_max()) if (!from_sys_trx_end->is_max())
continue; // Do not copy history rows. continue; // Do not copy history rows.
...@@ -10048,13 +10064,13 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, ...@@ -10048,13 +10064,13 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
break; break;
} }
if (keep_versioned && to->versioned_by_engine() && if (keep_versioned && to->versioned_by_engine() &&
!thd->variables.vers_ddl_survival) thd->variables.vers_alter_history != VERS_ALTER_HISTORY_SURVIVE)
{ {
to->s->versioned= false; to->s->versioned= false;
} }
error= to->file->ha_write_row(to->record[0]); error= to->file->ha_write_row(to->record[0]);
if (keep_versioned && to->versioned_by_engine() && if (keep_versioned && to->versioned_by_engine() &&
!thd->variables.vers_ddl_survival) thd->variables.vers_alter_history != VERS_ALTER_HISTORY_SURVIVE)
{ {
to->s->versioned= true; to->s->versioned= true;
} }
......
...@@ -15660,6 +15660,12 @@ set_expr_or_default: ...@@ -15660,6 +15660,12 @@ set_expr_or_default:
if ($$ == NULL) if ($$ == NULL)
MYSQL_YYABORT; MYSQL_YYABORT;
} }
| DROP
{
$$=new (thd->mem_root) Item_string_sys(thd, "DROP", 4);
if ($$ == NULL)
MYSQL_YYABORT;
}
; ;
/* Lock function */ /* Lock function */
......
...@@ -406,9 +406,12 @@ static Sys_var_mybool Sys_vers_innodb_algorithm_simple( ...@@ -406,9 +406,12 @@ static Sys_var_mybool Sys_vers_innodb_algorithm_simple(
SESSION_VAR(vers_innodb_algorithm_simple), CMD_LINE(OPT_ARG), SESSION_VAR(vers_innodb_algorithm_simple), CMD_LINE(OPT_ARG),
DEFAULT(TRUE)); DEFAULT(TRUE));
static Sys_var_mybool Sys_vers_ddl_survival( static const char *vers_alter_history_keywords[]= {"KEEP", "SURVIVE", "DROP",
"versioning_ddl_survival", "Use system versioning DDL survival feature", NULL};
SESSION_VAR(vers_ddl_survival), CMD_LINE(OPT_ARG), DEFAULT(FALSE)); static Sys_var_enum Sys_vers_alter_history(
"versioning_alter_history", "Versioning ALTER TABLE mode",
SESSION_VAR(vers_alter_history), CMD_LINE(OPT_ARG),
vers_alter_history_keywords, DEFAULT(VERS_ALTER_HISTORY_KEEP));
static Sys_var_ulonglong Sys_binlog_cache_size( static Sys_var_ulonglong Sys_binlog_cache_size(
"binlog_cache_size", "The size of the transactional cache for " "binlog_cache_size", "The size of the transactional cache for "
......
...@@ -6450,7 +6450,8 @@ ha_innobase::inplace_alter_table( ...@@ -6450,7 +6450,8 @@ ha_innobase::inplace_alter_table(
ctx->add_index, ctx->add_key_numbers, ctx->num_to_add_index, ctx->add_index, ctx->add_key_numbers, ctx->num_to_add_index,
altered_table, ctx->add_cols, ctx->col_map, altered_table, ctx->add_cols, ctx->col_map,
ctx->add_autoinc, ctx->sequence, ctx->skip_pk_sort, ctx->add_autoinc, ctx->sequence, ctx->skip_pk_sort,
ctx->m_stage, add_v, eval_table); ctx->m_stage, add_v, eval_table,
ha_alter_info->handler_flags & Alter_inplace_info::ALTER_DROP_HISTORICAL);
if (s_templ) { if (s_templ) {
ut_ad(ctx->need_rebuild() || ctx->num_to_add_vcol > 0 ut_ad(ctx->need_rebuild() || ctx->num_to_add_vcol > 0
......
...@@ -349,7 +349,8 @@ row_merge_build_indexes( ...@@ -349,7 +349,8 @@ row_merge_build_indexes(
bool skip_pk_sort, bool skip_pk_sort,
ut_stage_alter_t* stage, ut_stage_alter_t* stage,
const dict_add_v_col_t* add_v, const dict_add_v_col_t* add_v,
struct TABLE* eval_table) struct TABLE* eval_table,
bool drop_historical)
MY_ATTRIBUTE((warn_unused_result)); MY_ATTRIBUTE((warn_unused_result));
/********************************************************************//** /********************************************************************//**
......
...@@ -1797,7 +1797,8 @@ row_merge_read_clustered_index( ...@@ -1797,7 +1797,8 @@ row_merge_read_clustered_index(
double pct_cost, double pct_cost,
fil_space_crypt_t* crypt_data, fil_space_crypt_t* crypt_data,
row_merge_block_t* crypt_block, row_merge_block_t* crypt_block,
struct TABLE* eval_table) struct TABLE* eval_table,
bool drop_historical)
{ {
dict_index_t* clust_index; /* Clustered index */ dict_index_t* clust_index; /* Clustered index */
...@@ -2237,7 +2238,7 @@ row_merge_read_clustered_index( ...@@ -2237,7 +2238,7 @@ row_merge_read_clustered_index(
ut_ad(add_autoinc ut_ad(add_autoinc
< dict_table_get_n_user_cols(new_table)); < dict_table_get_n_user_cols(new_table));
bool row_is_historic = false; bool historical_row = false;
if (DICT_TF2_FLAG_IS_SET( if (DICT_TF2_FLAG_IS_SET(
new_table, DICT_TF2_VERSIONED)) { new_table, DICT_TF2_VERSIONED)) {
const dfield_t *dfield = dtuple_get_nth_field( const dfield_t *dfield = dtuple_get_nth_field(
...@@ -2245,7 +2246,7 @@ row_merge_read_clustered_index( ...@@ -2245,7 +2246,7 @@ row_merge_read_clustered_index(
const byte *data = static_cast<const byte *>( const byte *data = static_cast<const byte *>(
dfield_get_data(dfield)); dfield_get_data(dfield));
ut_ad(dfield_get_len(dfield) == 8); ut_ad(dfield_get_len(dfield) == 8);
row_is_historic = historical_row =
mach_read_from_8(data) != TRX_ID_MAX; mach_read_from_8(data) != TRX_ID_MAX;
} }
...@@ -2270,7 +2271,7 @@ row_merge_read_clustered_index( ...@@ -2270,7 +2271,7 @@ row_merge_read_clustered_index(
} }
ulonglong value; ulonglong value;
if (likely(!row_is_historic)) if (likely(!historical_row))
value = sequence++; value = sequence++;
else else
value = historic_auto_decrement--; value = historic_auto_decrement--;
...@@ -2302,8 +2303,9 @@ row_merge_read_clustered_index( ...@@ -2302,8 +2303,9 @@ row_merge_read_clustered_index(
} }
if (DICT_TF2_FLAG_IS_SET(old_table, DICT_TF2_VERSIONED)) { if (DICT_TF2_FLAG_IS_SET(old_table, DICT_TF2_VERSIONED)) {
if (DICT_TF2_FLAG_IS_SET( if (DICT_TF2_FLAG_IS_SET(new_table,
new_table, DICT_TF2_VERSIONED)) { DICT_TF2_VERSIONED) &&
!drop_historical) {
dfield_t *end = dtuple_get_nth_field( dfield_t *end = dtuple_get_nth_field(
row, new_table->vers_row_end); row, new_table->vers_row_end);
byte *data = static_cast<byte *>( byte *data = static_cast<byte *>(
...@@ -4674,7 +4676,8 @@ row_merge_build_indexes( ...@@ -4674,7 +4676,8 @@ row_merge_build_indexes(
bool skip_pk_sort, bool skip_pk_sort,
ut_stage_alter_t* stage, ut_stage_alter_t* stage,
const dict_add_v_col_t* add_v, const dict_add_v_col_t* add_v,
struct TABLE* eval_table) struct TABLE* eval_table,
bool drop_historical)
{ {
merge_file_t* merge_files; merge_file_t* merge_files;
row_merge_block_t* block; row_merge_block_t* block;
...@@ -4848,7 +4851,8 @@ row_merge_build_indexes( ...@@ -4848,7 +4851,8 @@ row_merge_build_indexes(
fts_sort_idx, psort_info, merge_files, key_numbers, fts_sort_idx, psort_info, merge_files, key_numbers,
n_indexes, add_cols, add_v, col_map, add_autoinc, n_indexes, add_cols, add_v, col_map, add_autoinc,
sequence, block, skip_pk_sort, &tmpfd, stage, sequence, block, skip_pk_sort, &tmpfd, stage,
pct_cost, crypt_data, crypt_block, eval_table); pct_cost, crypt_data, crypt_block, eval_table,
drop_historical);
stage->end_phase_read_pk(); stage->end_phase_read_pk();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment