1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

IB: TRT is not updated on ADD SYSTEM VERSIONING [fixes #413]

This commit is contained in:
Eugene Kosov
2017-12-20 22:46:28 +03:00
committed by GitHub
parent 6e530d4df5
commit acdfacee75
8 changed files with 135 additions and 19 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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())

View File

@ -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);

View File

@ -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 */

View File

@ -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<dict_table_t*>(new_table), 0))
.first->second;
time.set_versioned(0, true);
}
trx->op_info = "";
DBUG_RETURN(err);