Skip to content

Commit

Permalink
IB: TRT is not updated on ADD SYSTEM VERSIONING [fixes #413]
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgs committed Dec 20, 2017
1 parent 6e530d4 commit acdface
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 19 deletions.
11 changes: 7 additions & 4 deletions mysql-test/suite/versioning/r/alter.result
Original file line number Diff line number Diff line change
Expand Up @@ -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` (
Expand All @@ -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
Expand Down
56 changes: 56 additions & 0 deletions mysql-test/suite/versioning/r/trx_id.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
17 changes: 4 additions & 13 deletions mysql-test/suite/versioning/t/alter.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;

# 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);
alter table t drop column trx_start, drop column trx_end;

## 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;
Expand Down
53 changes: 53 additions & 0 deletions mysql-test/suite/versioning/t/trx_id.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 2 additions & 1 deletion sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 0 additions & 1 deletion storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
11 changes: 11 additions & 0 deletions storage/innobase/row/row0merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -2330,6 +2331,7 @@ row_merge_read_clustered_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:
Expand Down Expand Up @@ -2873,6 +2875,15 @@ row_merge_read_clustered_index(
}
}

if (vers_update_trt) {
trx_mod_table_time_t& time =
trx->mod_tables
.insert(trx_mod_tables_t::value_type(
const_cast<dict_table_t*>(new_table), 0))
.first->second;
time.set_versioned(0, true);
}

trx->op_info = "";

DBUG_RETURN(err);
Expand Down

0 comments on commit acdface

Please sign in to comment.