diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result index 679bee34d35..40d090ec72a 100644 --- a/mysql-test/suite/versioning/r/alter.result +++ b/mysql-test/suite/versioning/r/alter.result @@ -256,6 +256,7 @@ add period for system_time(trx_start, trx_end), add system versioning; call verify_vtq; No A B C D +1 1 1 1 1 show create table t; Table Create Table t CREATE TABLE `t` ( @@ -264,10 +265,12 @@ t CREATE TABLE `t` ( `trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END INVISIBLE, PERIOD FOR SYSTEM_TIME (`trx_start`, `trx_end`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING -create or replace table t( -a int -) engine=innodb; -insert into t values (1); +alter table t drop column trx_start, drop column trx_end; +call verify_vtq; +No A B C D +alter table t drop system versioning, algorithm=copy; +call verify_vtq; +No A B C D alter table t add system versioning, algorithm=copy; call verify_vtq; No A B C D diff --git a/mysql-test/suite/versioning/r/trx_id.result b/mysql-test/suite/versioning/r/trx_id.result index dc1380a77b0..c571ea70cf1 100644 --- a/mysql-test/suite/versioning/r/trx_id.result +++ b/mysql-test/suite/versioning/r/trx_id.result @@ -25,4 +25,60 @@ delete from t1; ERROR HY000: Temporal operation requires `mysql.transaction_registry` (@@system_versioning_transaction_registry). update t1 set x= 3; ERROR HY000: Temporal operation requires `mysql.transaction_registry` (@@system_versioning_transaction_registry). +# ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry +create function check_result (cond boolean) +returns char(50) deterministic +return if(cond = 1, '[CORRECT]', '[INCORRECT]'); +set @@system_versioning_alter_history=keep; +set global system_versioning_transaction_registry=on; +Warnings: +Warning 4144 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future. +create or replace table t1 (x int) engine innodb; +insert into t1 values (1); +alter table t1 +add column s bigint unsigned as row start, +add column e bigint unsigned as row end, +add period for system_time(s, e), +add system versioning, +algorithm=inplace; +select s from t1 into @trx_start; +select check_result(count(*) = 1) from mysql.transaction_registry where transaction_id = @trx_start; +check_result(count(*) = 1) +[CORRECT] +create or replace table t1 (x int) engine innodb; +select count(*) from mysql.transaction_registry into @tmp; +alter table t1 +add column s bigint unsigned as row start, +add column e bigint unsigned as row end, +add period for system_time(s, e), +add system versioning, +algorithm=inplace; +select check_result(count(*) = @tmp) from mysql.transaction_registry; +check_result(count(*) = @tmp) +[CORRECT] +create or replace table t1 (x int) engine innodb; +insert into t1 values (1); +alter table t1 +add column s bigint unsigned as row start, +add column e bigint unsigned as row end, +add period for system_time(s, e), +add system versioning, +algorithm=copy; +select s from t1 into @trx_start; +select check_result(count(*) = 1) from mysql.transaction_registry where transaction_id = @trx_start; +check_result(count(*) = 1) +[CORRECT] +create or replace table t1 (x int) engine innodb; +select count(*) from mysql.transaction_registry into @tmp; +alter table t1 +add column s bigint unsigned as row start, +add column e bigint unsigned as row end, +add period for system_time(s, e), +add system versioning, +algorithm=copy; +select check_result(count(*) = @tmp) from mysql.transaction_registry; +check_result(count(*) = @tmp) +[CORRECT] drop table t1; +set global system_versioning_transaction_registry=off; +drop function check_result; diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index 0a3beaf90fa..db0b63682a9 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -165,20 +165,11 @@ alter table t 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; +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 +call verify_vtq; +alter table t drop system versioning, algorithm=copy; +call verify_vtq; alter table t add system versioning, algorithm=copy; call verify_vtq; diff --git a/mysql-test/suite/versioning/t/trx_id.test b/mysql-test/suite/versioning/t/trx_id.test index daf4adb3181..ce8f36adefc 100644 --- a/mysql-test/suite/versioning/t/trx_id.test +++ b/mysql-test/suite/versioning/t/trx_id.test @@ -29,4 +29,57 @@ delete from t1; --error ER_VERS_TRT_IS_DISABLED update t1 set x= 3; +--echo # ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry +create function check_result (cond boolean) + returns char(50) deterministic + return if(cond = 1, '[CORRECT]', '[INCORRECT]'); + +set @@system_versioning_alter_history=keep; +set global system_versioning_transaction_registry=on; + +create or replace table t1 (x int) engine innodb; +insert into t1 values (1); +alter table t1 + add column s bigint unsigned as row start, + add column e bigint unsigned as row end, + add period for system_time(s, e), + add system versioning, + algorithm=inplace; +select s from t1 into @trx_start; +select check_result(count(*) = 1) from mysql.transaction_registry where transaction_id = @trx_start; + +create or replace table t1 (x int) engine innodb; +select count(*) from mysql.transaction_registry into @tmp; +alter table t1 + add column s bigint unsigned as row start, + add column e bigint unsigned as row end, + add period for system_time(s, e), + add system versioning, + algorithm=inplace; +select check_result(count(*) = @tmp) from mysql.transaction_registry; + +create or replace table t1 (x int) engine innodb; +insert into t1 values (1); +alter table t1 + add column s bigint unsigned as row start, + add column e bigint unsigned as row end, + add period for system_time(s, e), + add system versioning, + algorithm=copy; +select s from t1 into @trx_start; +select check_result(count(*) = 1) from mysql.transaction_registry where transaction_id = @trx_start; + +create or replace table t1 (x int) engine innodb; +select count(*) from mysql.transaction_registry into @tmp; +alter table t1 + add column s bigint unsigned as row start, + add column e bigint unsigned as row end, + add period for system_time(s, e), + add system versioning, + algorithm=copy; +select check_result(count(*) = @tmp) from mysql.transaction_registry; + + drop table t1; +set global system_versioning_transaction_registry=off; +drop function check_result; diff --git a/sql/handler.cc b/sql/handler.cc index d5e3dbc66a8..17e93ad7346 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1415,7 +1415,8 @@ int ha_commit_trans(THD *thd, bool all) } #if 1 // FIXME: This should be done in ha_prepare(). - if (rw_trans) + if (rw_trans || (thd->lex->sql_command == SQLCOM_ALTER_TABLE && + thd->lex->alter_info.flags & Alter_info::ALTER_ADD_SYSTEM_VERSIONING)) { ulonglong trx_start_id= 0, trx_end_id= 0; for (Ha_trx_info *ha_info= trans->ha_list; ha_info; ha_info= ha_info->next()) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index f1b5bafb371..06d3551f77e 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -3638,7 +3638,6 @@ static ulonglong innodb_prepare_commit_versioned(THD* thd, ulonglong *trx_id) t != trx->mod_tables.end(); t++) { if (t->second.is_trx_versioned()) { DBUG_ASSERT(t->first->versioned()); - DBUG_ASSERT(trx->undo_no); DBUG_ASSERT(trx->rsegs.m_redo.rseg); mutex_enter(&trx_sys->mutex); diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 346a94e6fa0..d1ba5ab92f7 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -88,6 +88,8 @@ static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_REBUILD | Alter_inplace_info::ALTER_STORED_COLUMN_TYPE */ | Alter_inplace_info::ALTER_COLUMN_UNVERSIONED + | Alter_inplace_info::ALTER_ADD_SYSTEM_VERSIONING + | Alter_inplace_info::ALTER_DROP_SYSTEM_VERSIONING ; /** Operations that require changes to data */ diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index 23018f68536..3f906539ed8 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -1745,6 +1745,7 @@ row_merge_read_clustered_index( char new_sys_trx_start[8]; char new_sys_trx_end[8]; byte any_autoinc_data[8] = {0}; + bool vers_update_trt = false; DBUG_ENTER("row_merge_read_clustered_index"); @@ -2330,6 +2331,7 @@ end_of_index: dtuple_get_nth_field(row, new_table->vers_end); dfield_set_data(start, new_sys_trx_start, 8); dfield_set_data(end, new_sys_trx_end, 8); + vers_update_trt = true; } write_buffers: @@ -2873,6 +2875,15 @@ wait_again: } } + if (vers_update_trt) { + trx_mod_table_time_t& time = + trx->mod_tables + .insert(trx_mod_tables_t::value_type( + const_cast(new_table), 0)) + .first->second; + time.set_versioned(0, true); + } + trx->op_info = ""; DBUG_RETURN(err);