Skip to content

Commit

Permalink
IB: optimized update for non-versioned fields
Browse files Browse the repository at this point in the history
Fixes #53
  • Loading branch information
midenok committed May 5, 2017
1 parent 01c9d1c commit 5dea516
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 24 deletions.
37 changes: 25 additions & 12 deletions mysql-test/suite/versioning/r/update.result
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ begin
set @str= concat('
create table t1 (
id bigint primary key,
a int,
b int without system versioning)
x int,
y int without system versioning)
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1 values(1, 1, 1);
set @ins_t= now(6);
select sys_trx_start into @tmp1 from t1;
update t1 set a=11, b=11 where id=1;
select @tmp1 < sys_trx_start, a, b from t1;
update t1 set x= 11, y= 11 where id = 1;
select @tmp1 < sys_trx_start as A1, x, y from t1;
select sys_trx_start into @tmp1 from t1;
update t1 set b=1 where id=1;
select @tmp1 = sys_trx_start, b from t1;
update t1 set y= 1 where id = 1;
select @tmp1 = sys_trx_start as A2, x from t1;
drop table t1;
end~~
create procedure test_03(
Expand Down Expand Up @@ -292,15 +292,15 @@ x y
8 8000
9 9000
call test_02('timestamp(6)', 'myisam', 'sys_end');
@tmp1 < sys_trx_start a b
A1 x y
1 11 11
@tmp1 = sys_trx_start b
1 1
A2 x
1 11
call test_02('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
@tmp1 < sys_trx_start a b
A1 x y
1 11 11
@tmp1 = sys_trx_start b
0 1
A2 x
1 11
call test_03('timestamp(6)', 'myisam', 'sys_end');
x y
1 1
Expand Down Expand Up @@ -489,6 +489,15 @@ B1 salary
1 2500
B2 salary
1 2500
call test_07('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
A1 name
1 Jerry
A2 name
1 Jerry
B1 salary
1 2500
B2 salary
1 2500
call verify_vtq;
No A B C D
1 1 1 1 1
Expand All @@ -509,6 +518,10 @@ No A B C D
16 1 1 1 1
17 1 1 1 1
18 1 1 1 1
19 1 1 1 1
20 1 1 1 1
21 1 1 1 1
22 1 1 1 1
drop procedure test_01;
drop procedure test_02;
drop procedure test_03;
Expand Down
1 change: 1 addition & 0 deletions mysql-test/suite/versioning/t/auto_increment.test
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ call verify_vtq;

drop procedure test_01;
drop procedure verify_vtq;

15 changes: 7 additions & 8 deletions mysql-test/suite/versioning/t/update.test
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ begin
set @str= concat('
create table t1 (
id bigint primary key,
a int,
b int without system versioning)
x int,
y int without system versioning)
with system versioning
engine ', engine);
prepare stmt from @str; execute stmt; drop prepare stmt;
insert into t1 values(1, 1, 1);
set @ins_t= now(6);
select sys_trx_start into @tmp1 from t1;
update t1 set a=11, b=11 where id=1;
select @tmp1 < sys_trx_start, a, b from t1;
update t1 set x= 11, y= 11 where id = 1;
select @tmp1 < sys_trx_start as A1, x, y from t1;

select sys_trx_start into @tmp1 from t1;
update t1 set b=1 where id=1;
select @tmp1 = sys_trx_start, b from t1;
update t1 set y= 1 where id = 1;
select @tmp1 = sys_trx_start as A2, x from t1;

drop table t1;
end~~
Expand Down Expand Up @@ -252,8 +252,7 @@ call test_06('timestamp(6)', 'myisam', 'sys_end');
call test_06('bigint unsigned', 'innodb', 'commit_ts(sys_end)');

call test_07('timestamp(6)', 'myisam', 'sys_end');
# Issue #53
# call test_07('bigint unsigned', 'innodb', 'commit_ts(sys_end)');
call test_07('bigint unsigned', 'innodb', 'commit_ts(sys_end)');

call verify_vtq;

Expand Down
18 changes: 17 additions & 1 deletion storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8959,6 +8959,8 @@ calc_row_difference(
/* We use upd_buff to convert changed fields */
buf = (byte*) upd_buff;

prebuilt->upd_node->versioned = false;

for (i = 0; i < table->s->fields; i++) {
field = table->field[i];
bool is_virtual = innobase_is_v_fld(field);
Expand Down Expand Up @@ -9199,6 +9201,13 @@ calc_row_difference(
}
n_changed++;

if (!prebuilt->upd_node->versioned &&
DICT_TF2_FLAG_IS_SET(prebuilt->table, DICT_TF2_VERSIONED) &&
!(field->flags & WITHOUT_SYSTEM_VERSIONING_FLAG))
{
prebuilt->upd_node->versioned = true;
}

/* If an FTS indexed column was changed by this
UPDATE then we need to inform the FTS sub-system.

Expand Down Expand Up @@ -9303,6 +9312,13 @@ calc_row_difference(
innodb_table, ufield, &trx->fts_next_doc_id);

++n_changed;

if (!prebuilt->upd_node->versioned &&
DICT_TF2_FLAG_IS_SET(prebuilt->table, DICT_TF2_VERSIONED) &&
!(field->flags & WITHOUT_SYSTEM_VERSIONING_FLAG))
{
prebuilt->upd_node->versioned = true;
}
} else {
/* We have a Doc ID column, but none of FTS indexed
columns are touched, nor the Doc ID column, so set
Expand Down Expand Up @@ -9486,7 +9502,7 @@ ha_innobase::update_row(

error = row_update_for_mysql((byte*) old_row, m_prebuilt);

if (error == DB_SUCCESS && DICT_TF2_FLAG_IS_SET(m_prebuilt->table, DICT_TF2_VERSIONED)) {
if (error == DB_SUCCESS && m_prebuilt->upd_node->versioned) {
if (trx->id != static_cast<trx_id_t>(table->vers_start_field()->val_int()))
error = row_insert_for_mysql((byte*) old_row, m_prebuilt, true);
}
Expand Down
1 change: 1 addition & 0 deletions storage/innobase/include/row0upd.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ struct upd_node_t{
compilation; speeds up execution:
UPD_NODE_NO_ORD_CHANGE and
UPD_NODE_NO_SIZE_CHANGE, ORed */
bool versioned;/* update is versioned */
/*----------------------*/
/* Local storage for this graph node */
ulint state; /*!< node execution state */
Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/row/row0ins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@ row_ins_sec_index_entry_low(

cursor.thr = thr;
cursor.rtr_info = NULL;
ut_ad(thr_get_trx(thr)->id != 0);
ut_ad(trx && trx->id != 0 || thr_get_trx(thr)->id != 0);

mtr_start(&mtr);
mtr.set_named_space(index->space);
Expand Down Expand Up @@ -3890,7 +3890,7 @@ void vers_notify_vtq(trx_t* trx)
timeval begin_ts, commit_ts;
begin_ts.tv_sec = trx->start_time;
begin_ts.tv_usec = trx->start_time_micro;
ut_usectime((ulint *)&commit_ts.tv_sec, (ulint *)&commit_ts.tv_usec);
ut_usectime((ulong*)&commit_ts.tv_sec, (ulong*)&commit_ts.tv_usec);

dict_table_copy_types(row, dict_sys->sys_vtq);
set_row_field_8(row, DICT_FLD__SYS_VTQ__TRX_ID, trx->id, heap);
Expand Down
3 changes: 2 additions & 1 deletion storage/innobase/row/row0mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,8 @@ row_update_for_mysql_using_upd_graph(
prebuilt->clust_pcur);
}

if (DICT_TF2_FLAG_IS_SET(node->table, DICT_TF2_VERSIONED))
if (DICT_TF2_FLAG_IS_SET(node->table, DICT_TF2_VERSIONED) &&
(node->is_delete || node->versioned))
{
/* System Versioning: modify update vector to set
sys_trx_start (or sys_trx_end in case of DELETE)
Expand Down
2 changes: 2 additions & 0 deletions storage/innobase/row/row0upd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ upd_node_create(
node->common.type = QUE_NODE_UPDATE;
node->state = UPD_NODE_UPDATE_CLUSTERED;
node->heap = mem_heap_create(128);
node->cmpl_info = 0;
node->versioned = false;
node->magic_n = UPD_NODE_MAGIC_N;

return(node);
Expand Down

0 comments on commit 5dea516

Please sign in to comment.