Skip to content
/ server Public

Commit acdface

Browse files
authored
IB: TRT is not updated on ADD SYSTEM VERSIONING [fixes #413]
1 parent 6e530d4 commit acdface

File tree

8 files changed

+135
-19
lines changed

8 files changed

+135
-19
lines changed

mysql-test/suite/versioning/r/alter.result

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ add period for system_time(trx_start, trx_end),
256256
add system versioning;
257257
call verify_vtq;
258258
No A B C D
259+
1 1 1 1 1
259260
show create table t;
260261
Table Create Table
261262
t CREATE TABLE `t` (
@@ -264,10 +265,12 @@ t CREATE TABLE `t` (
264265
`trx_end` bigint(20) unsigned GENERATED ALWAYS AS ROW END INVISIBLE,
265266
PERIOD FOR SYSTEM_TIME (`trx_start`, `trx_end`)
266267
) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
267-
create or replace table t(
268-
a int
269-
) engine=innodb;
270-
insert into t values (1);
268+
alter table t drop column trx_start, drop column trx_end;
269+
call verify_vtq;
270+
No A B C D
271+
alter table t drop system versioning, algorithm=copy;
272+
call verify_vtq;
273+
No A B C D
271274
alter table t add system versioning, algorithm=copy;
272275
call verify_vtq;
273276
No A B C D

mysql-test/suite/versioning/r/trx_id.result

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,60 @@ delete from t1;
2525
ERROR HY000: Temporal operation requires `mysql.transaction_registry` (@@system_versioning_transaction_registry).
2626
update t1 set x= 3;
2727
ERROR HY000: Temporal operation requires `mysql.transaction_registry` (@@system_versioning_transaction_registry).
28+
# ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry
29+
create function check_result (cond boolean)
30+
returns char(50) deterministic
31+
return if(cond = 1, '[CORRECT]', '[INCORRECT]');
32+
set @@system_versioning_alter_history=keep;
33+
set global system_versioning_transaction_registry=on;
34+
Warnings:
35+
Warning 4144 Transaction-based system versioning is EXPERIMENTAL and is subject to change in future.
36+
create or replace table t1 (x int) engine innodb;
37+
insert into t1 values (1);
38+
alter table t1
39+
add column s bigint unsigned as row start,
40+
add column e bigint unsigned as row end,
41+
add period for system_time(s, e),
42+
add system versioning,
43+
algorithm=inplace;
44+
select s from t1 into @trx_start;
45+
select check_result(count(*) = 1) from mysql.transaction_registry where transaction_id = @trx_start;
46+
check_result(count(*) = 1)
47+
[CORRECT]
48+
create or replace table t1 (x int) engine innodb;
49+
select count(*) from mysql.transaction_registry into @tmp;
50+
alter table t1
51+
add column s bigint unsigned as row start,
52+
add column e bigint unsigned as row end,
53+
add period for system_time(s, e),
54+
add system versioning,
55+
algorithm=inplace;
56+
select check_result(count(*) = @tmp) from mysql.transaction_registry;
57+
check_result(count(*) = @tmp)
58+
[CORRECT]
59+
create or replace table t1 (x int) engine innodb;
60+
insert into t1 values (1);
61+
alter table t1
62+
add column s bigint unsigned as row start,
63+
add column e bigint unsigned as row end,
64+
add period for system_time(s, e),
65+
add system versioning,
66+
algorithm=copy;
67+
select s from t1 into @trx_start;
68+
select check_result(count(*) = 1) from mysql.transaction_registry where transaction_id = @trx_start;
69+
check_result(count(*) = 1)
70+
[CORRECT]
71+
create or replace table t1 (x int) engine innodb;
72+
select count(*) from mysql.transaction_registry into @tmp;
73+
alter table t1
74+
add column s bigint unsigned as row start,
75+
add column e bigint unsigned as row end,
76+
add period for system_time(s, e),
77+
add system versioning,
78+
algorithm=copy;
79+
select check_result(count(*) = @tmp) from mysql.transaction_registry;
80+
check_result(count(*) = @tmp)
81+
[CORRECT]
2882
drop table t1;
83+
set global system_versioning_transaction_registry=off;
84+
drop function check_result;

mysql-test/suite/versioning/t/alter.test

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,11 @@ alter table t
165165
call verify_vtq;
166166

167167
show create table t;
168-
## FIXME: #413 TRT is not updated on ADD SYSTEM VERSIONING
169-
# alter table t drop column trx_start, drop column trx_end;
170-
171-
# call verify_vtq;
172-
# alter table t drop system versioning, algorithm=copy;
173-
# call verify_vtq;
174-
175-
create or replace table t(
176-
a int
177-
) engine=innodb;
178-
179-
insert into t values (1);
168+
alter table t drop column trx_start, drop column trx_end;
180169

181-
## FIXME END
170+
call verify_vtq;
171+
alter table t drop system versioning, algorithm=copy;
172+
call verify_vtq;
182173

183174
alter table t add system versioning, algorithm=copy;
184175
call verify_vtq;

mysql-test/suite/versioning/t/trx_id.test

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,57 @@ delete from t1;
2929
--error ER_VERS_TRT_IS_DISABLED
3030
update t1 set x= 3;
3131

32+
--echo # ALTER ADD SYSTEM VERSIONING should write to mysql.transaction_registry
33+
create function check_result (cond boolean)
34+
returns char(50) deterministic
35+
return if(cond = 1, '[CORRECT]', '[INCORRECT]');
36+
37+
set @@system_versioning_alter_history=keep;
38+
set global system_versioning_transaction_registry=on;
39+
40+
create or replace table t1 (x int) engine innodb;
41+
insert into t1 values (1);
42+
alter table t1
43+
add column s bigint unsigned as row start,
44+
add column e bigint unsigned as row end,
45+
add period for system_time(s, e),
46+
add system versioning,
47+
algorithm=inplace;
48+
select s from t1 into @trx_start;
49+
select check_result(count(*) = 1) from mysql.transaction_registry where transaction_id = @trx_start;
50+
51+
create or replace table t1 (x int) engine innodb;
52+
select count(*) from mysql.transaction_registry into @tmp;
53+
alter table t1
54+
add column s bigint unsigned as row start,
55+
add column e bigint unsigned as row end,
56+
add period for system_time(s, e),
57+
add system versioning,
58+
algorithm=inplace;
59+
select check_result(count(*) = @tmp) from mysql.transaction_registry;
60+
61+
create or replace table t1 (x int) engine innodb;
62+
insert into t1 values (1);
63+
alter table t1
64+
add column s bigint unsigned as row start,
65+
add column e bigint unsigned as row end,
66+
add period for system_time(s, e),
67+
add system versioning,
68+
algorithm=copy;
69+
select s from t1 into @trx_start;
70+
select check_result(count(*) = 1) from mysql.transaction_registry where transaction_id = @trx_start;
71+
72+
create or replace table t1 (x int) engine innodb;
73+
select count(*) from mysql.transaction_registry into @tmp;
74+
alter table t1
75+
add column s bigint unsigned as row start,
76+
add column e bigint unsigned as row end,
77+
add period for system_time(s, e),
78+
add system versioning,
79+
algorithm=copy;
80+
select check_result(count(*) = @tmp) from mysql.transaction_registry;
81+
82+
3283
drop table t1;
84+
set global system_versioning_transaction_registry=off;
85+
drop function check_result;

sql/handler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,8 @@ int ha_commit_trans(THD *thd, bool all)
14151415
}
14161416

14171417
#if 1 // FIXME: This should be done in ha_prepare().
1418-
if (rw_trans)
1418+
if (rw_trans || (thd->lex->sql_command == SQLCOM_ALTER_TABLE &&
1419+
thd->lex->alter_info.flags & Alter_info::ALTER_ADD_SYSTEM_VERSIONING))
14191420
{
14201421
ulonglong trx_start_id= 0, trx_end_id= 0;
14211422
for (Ha_trx_info *ha_info= trans->ha_list; ha_info; ha_info= ha_info->next())

storage/innobase/handler/ha_innodb.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3638,7 +3638,6 @@ static ulonglong innodb_prepare_commit_versioned(THD* thd, ulonglong *trx_id)
36383638
t != trx->mod_tables.end(); t++) {
36393639
if (t->second.is_trx_versioned()) {
36403640
DBUG_ASSERT(t->first->versioned());
3641-
DBUG_ASSERT(trx->undo_no);
36423641
DBUG_ASSERT(trx->rsegs.m_redo.rseg);
36433642

36443643
mutex_enter(&trx_sys->mutex);

storage/innobase/handler/handler0alter.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_REBUILD
8888
| Alter_inplace_info::ALTER_STORED_COLUMN_TYPE
8989
*/
9090
| Alter_inplace_info::ALTER_COLUMN_UNVERSIONED
91+
| Alter_inplace_info::ALTER_ADD_SYSTEM_VERSIONING
92+
| Alter_inplace_info::ALTER_DROP_SYSTEM_VERSIONING
9193
;
9294

9395
/** Operations that require changes to data */

storage/innobase/row/row0merge.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,7 @@ row_merge_read_clustered_index(
17451745
char new_sys_trx_start[8];
17461746
char new_sys_trx_end[8];
17471747
byte any_autoinc_data[8] = {0};
1748+
bool vers_update_trt = false;
17481749

17491750
DBUG_ENTER("row_merge_read_clustered_index");
17501751

@@ -2330,6 +2331,7 @@ row_merge_read_clustered_index(
23302331
dtuple_get_nth_field(row, new_table->vers_end);
23312332
dfield_set_data(start, new_sys_trx_start, 8);
23322333
dfield_set_data(end, new_sys_trx_end, 8);
2334+
vers_update_trt = true;
23332335
}
23342336

23352337
write_buffers:
@@ -2873,6 +2875,15 @@ row_merge_read_clustered_index(
28732875
}
28742876
}
28752877

2878+
if (vers_update_trt) {
2879+
trx_mod_table_time_t& time =
2880+
trx->mod_tables
2881+
.insert(trx_mod_tables_t::value_type(
2882+
const_cast<dict_table_t*>(new_table), 0))
2883+
.first->second;
2884+
time.set_versioned(0, true);
2885+
}
2886+
28762887
trx->op_info = "";
28772888

28782889
DBUG_RETURN(err);

0 commit comments

Comments
 (0)