diff --git a/mysql-test/suite/versioning/r/update.result b/mysql-test/suite/versioning/r/update.result index 06fb2186d7d5a..ff0874799b02b 100644 --- a/mysql-test/suite/versioning/r/update.result +++ b/mysql-test/suite/versioning/r/update.result @@ -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( @@ -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 @@ -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 @@ -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; diff --git a/mysql-test/suite/versioning/t/update.test b/mysql-test/suite/versioning/t/update.test index f875a41ad3f6e..9ca7fee412665 100644 --- a/mysql-test/suite/versioning/t/update.test +++ b/mysql-test/suite/versioning/t/update.test @@ -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~~ @@ -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; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index be4c7811faad6..281fcc5eae0f7 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -8379,6 +8379,8 @@ calc_row_difference( /* We use upd_buff to convert changed fields */ buf = (byte*) upd_buff; + prebuilt->upd_node->versioned = false; + for (sql_idx = 0; sql_idx < n_fields; sql_idx++) { field = table->field[sql_idx]; if (!field->stored_in_db()) @@ -8489,6 +8491,13 @@ calc_row_difference( &prebuilt->table->cols[innodb_idx], clust_index); 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. @@ -8592,6 +8601,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 @@ -8765,7 +8781,7 @@ ha_innobase::update_row( error = row_update_for_mysql((byte*) old_row, prebuilt); - if (error == DB_SUCCESS && DICT_TF2_FLAG_IS_SET(prebuilt->table, DICT_TF2_VERSIONED)) { + if (error == DB_SUCCESS && prebuilt->upd_node->versioned) { if (trx->id != static_cast(table->vers_start_field()->val_int())) error = row_insert_for_mysql((byte*) old_row, prebuilt, true); } diff --git a/storage/innobase/include/row0upd.h b/storage/innobase/include/row0upd.h index 27dedeb65a7f6..733268989327e 100644 --- a/storage/innobase/include/row0upd.h +++ b/storage/innobase/include/row0upd.h @@ -475,6 +475,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 */ diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 4627f21c29c48..04d249a06cf1e 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -1807,7 +1807,8 @@ row_update_for_mysql( &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) diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index 0ea4865d15f8d..67085ab2b0350 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -498,6 +498,7 @@ upd_node_create( node->magic_n = UPD_NODE_MAGIC_N; node->cmpl_info = 0; + node->versioned = false; return(node); }