Skip to content

Commit

Permalink
IB: get template with virtual columns [#365 bug 1]
Browse files Browse the repository at this point in the history
Affected tests (forced mode): binlog_encryption.encrypted_slave
  • Loading branch information
midenok committed Nov 29, 2017
1 parent f924a94 commit 47ea526
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
10 changes: 10 additions & 0 deletions mysql-test/suite/versioning/r/insert.result
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,16 @@ insert into t2(x) values (1);
insert into t1(x) values (1);
ERROR HY000: Some versioned DML requires `transaction_registry` to be set to ON.
set global transaction_registry= on;
create or replace table t1 (
x int,
y int as (x) virtual
) engine=innodb with system versioning;
insert into t1 values (1, null);
update t1 set x= x + 1;
select *, sys_trx_end = 18446744073709551615 as current from t1 for system_time all;
x y current
2 2 1
1 1 0
drop table t1;
drop table t2;
drop procedure test_01;
Expand Down
9 changes: 9 additions & 0 deletions mysql-test/suite/versioning/t/insert.test
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@ insert into t2(x) values (1);
insert into t1(x) values (1);
set global transaction_registry= on;

# virtual columns
create or replace table t1 (
x int,
y int as (x) virtual
) engine=innodb with system versioning;
insert into t1 values (1, null);
update t1 set x= x + 1;
select *, sys_trx_end = 18446744073709551615 as current from t1 for system_time all;

drop table t1;
drop table t2;

Expand Down
14 changes: 14 additions & 0 deletions storage/innobase/include/row0mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,20 @@ struct row_prebuilt_t {

/** The MySQL table object */
TABLE* m_mysql_table;

/** Get template by column number */
const mysql_row_templ_t* get_template_by_col(ulint col) const
{
ut_a(col < n_template);
ut_a(mysql_template);
for (int i = col; i < n_template; ++i)
{
const mysql_row_templ_t* templ = mysql_template + i;
if (!templ->is_virtual && templ->col_no == col)
return templ;
}
return NULL;
}
};

/** Callback for row_mysql_sys_index_iterate() */
Expand Down
8 changes: 4 additions & 4 deletions storage/innobase/row/row0mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1517,17 +1517,17 @@ row_insert_for_mysql(
ut_ad(table->vers_start != table->vers_end);
/* Return back modified fields into mysql_rec, so that
upper logic may benefit from it (f.ex. 'on duplicate key'). */
const mysql_row_templ_t* t = &prebuilt->mysql_template[table->vers_end];
ut_ad(t->mysql_col_len == 8);
const mysql_row_templ_t* t = prebuilt->get_template_by_col(table->vers_end);
ut_ad(t && t->mysql_col_len == 8);

if (ins_mode == ROW_INS_HISTORICAL) {
set_tuple_col_8(node->row, table->vers_end, trx->id, node->vers_end_buf);
}
else /* ROW_INS_VERSIONED */ {
set_tuple_col_8(node->row, table->vers_end, TRX_ID_MAX, node->vers_end_buf);
int8store(&mysql_rec[t->mysql_col_offset], TRX_ID_MAX);
t = &prebuilt->mysql_template[table->vers_start];
ut_ad(t->mysql_col_len == 8);
t = prebuilt->get_template_by_col(table->vers_start);
ut_ad(t && t->mysql_col_len == 8);
set_tuple_col_8(node->row, table->vers_start, trx->id, node->vers_start_buf);
int8store(&mysql_rec[t->mysql_col_offset], trx->id);
}
Expand Down

0 comments on commit 47ea526

Please sign in to comment.