diff options
author | Aleksey Midenkov <midenok@gmail.com> | 2017-11-23 17:41:27 +0300 |
---|---|---|
committer | Aleksey Midenkov <midenok@gmail.com> | 2017-11-23 18:31:55 +0300 |
commit | cbe93291e4391dc5788c022e92d1baf17ca33625 (patch) | |
tree | 9a541d4055c8b9ffdaf36b064e294ecbc8b580d5 | |
parent | b612f3baa25e6801e9c3bcaca464c9d152a32820 (diff) | |
download | mariadb-git-cbe93291e4391dc5788c022e92d1baf17ca33625.tar.gz |
SQL,IB: add auto_inc copy mode fix [#347]
Related to #212.
Extra update of sys_trx_start removed [#87].
-rw-r--r-- | mysql-test/suite/versioning/r/alter.result | 29 | ||||
-rw-r--r-- | mysql-test/suite/versioning/t/alter.test | 7 | ||||
-rw-r--r-- | sql/handler.cc | 2 | ||||
-rw-r--r-- | sql/sql_table.cc | 7 | ||||
-rw-r--r-- | sql/table.cc | 4 | ||||
-rw-r--r-- | sql/table.h | 7 | ||||
-rw-r--r-- | sql/vtmd.cc | 8 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 6 | ||||
-rw-r--r-- | storage/innobase/row/row0merge.cc | 16 |
9 files changed, 48 insertions, 38 deletions
diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result index 0e116018125..a24110013e8 100644 --- a/mysql-test/suite/versioning/r/alter.result +++ b/mysql-test/suite/versioning/r/alter.result @@ -466,10 +466,18 @@ Table Create Table t CREATE TABLE `t` ( `a` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 +call verify_vtq; +No A B C D create or replace table t (a int) with system versioning engine=innodb; insert into t values (1), (2), (3); delete from t where a<3; +call verify_vtq; +No A B C D +1 1 1 1 1 +2 1 1 1 1 alter table t add b int auto_increment unique; +call verify_vtq; +No A B C D select * from t for system_time all; a b 1 -1 @@ -482,6 +490,9 @@ a b 2 -2 3 1 4 2 +call verify_vtq; +No A B C D +1 1 1 1 1 create or replace table t (a int) with system versioning; insert into t values (1), (2), (3); delete from t where a<3; @@ -501,7 +512,13 @@ a b create or replace table t (a int) with system versioning engine=innodb; insert into t values (1), (2), (3); delete from t where a<3; +call verify_vtq; +No A B C D +1 1 1 1 1 +2 1 1 1 1 alter table t add b tinyint auto_increment unique; +call verify_vtq; +No A B C D select * from t for system_time all; a b 1 -1 @@ -514,6 +531,9 @@ a b 2 -2 3 1 4 2 +call verify_vtq; +No A B C D +1 1 1 1 1 create or replace table t (a int) with system versioning; insert into t values (1), (2), (3); delete from t where a<3; @@ -610,15 +630,6 @@ call verify_vtq; No A B C D 1 1 1 1 1 2 1 1 1 1 -3 1 1 1 1 -4 1 1 1 1 -5 1 1 1 1 -6 1 1 1 1 -7 1 1 1 1 -8 1 1 1 1 -9 1 1 1 1 -10 1 1 1 1 -11 1 1 1 1 drop table t; drop procedure verify_vtq; drop procedure innodb_verify_vtq; diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index aca8a73f846..817549168bc 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -194,14 +194,18 @@ select * from t for system_time all; alter table t drop system versioning, algorithm=copy; show create table t; +call verify_vtq; create or replace table t (a int) with system versioning engine=innodb; insert into t values (1), (2), (3); delete from t where a<3; +call verify_vtq; alter table t add b int auto_increment unique; +call verify_vtq; select * from t for system_time all; insert into t values (4, NULL); select * from t for system_time all; +call verify_vtq; create or replace table t (a int) with system versioning; insert into t values (1), (2), (3); @@ -214,10 +218,13 @@ select * from t for system_time all; create or replace table t (a int) with system versioning engine=innodb; insert into t values (1), (2), (3); delete from t where a<3; +call verify_vtq; alter table t add b tinyint auto_increment unique; +call verify_vtq; select * from t for system_time all; insert into t values (4, NULL); select * from t for system_time all; +call verify_vtq; create or replace table t (a int) with system versioning; insert into t values (1), (2), (3); diff --git a/sql/handler.cc b/sql/handler.cc index 4bcfd92dfd3..97ade27d933 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -3036,7 +3036,7 @@ int handler::update_auto_increment() DBUG_ENTER("handler::update_auto_increment"); // System Versioning: handle ALTER ADD COLUMN AUTO_INCREMENT - if (thd->lex->sql_command == SQLCOM_ALTER_TABLE && table->versioned_by_sql()) + if (thd->lex->sql_command == SQLCOM_ALTER_TABLE && table->versioned()) { Field *end= table->vers_end_field(); DBUG_ASSERT(end); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 74eda09f34b..640aa6e29bb 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -10180,14 +10180,9 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, if (keep_versioned && to->versioned_by_engine() && thd->variables.vers_alter_history != VERS_ALTER_HISTORY_SURVIVE) { - to->s->versioned= false; + to->vers_write= false; } error= to->file->ha_write_row(to->record[0]); - if (keep_versioned && to->versioned_by_engine() && - thd->variables.vers_alter_history != VERS_ALTER_HISTORY_SURVIVE) - { - to->s->versioned= true; - } to->auto_increment_field_not_null= FALSE; if (error) { diff --git a/sql/table.cc b/sql/table.cc index 01693719585..32b0d954e9f 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3216,9 +3216,13 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share, *fptr++ = outparam->field[i]; } (*fptr)= 0; // End marker + outparam->vers_write= true; } else + { outparam->non_generated_field= NULL; + outparam->vers_write= false; + } if (share->found_next_number_field) outparam->found_next_number_field= diff --git a/sql/table.h b/sql/table.h index 5da230f3606..3469ec4b0b4 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1505,6 +1505,7 @@ public: /** System Versioning support */ + bool vers_write; bool versioned() const { @@ -1512,6 +1513,12 @@ public: return s->versioned; } + bool versioned_write() const + { + DBUG_ASSERT(versioned() || !vers_write); + return vers_write; + } + /* Versioned by SQL layer */ bool versioned_by_sql() const { diff --git a/sql/vtmd.cc b/sql/vtmd.cc index b752f828972..ad03ea02156 100644 --- a/sql/vtmd.cc +++ b/sql/vtmd.cc @@ -186,9 +186,9 @@ VTMD_table::update(THD *thd, const char* archive_name) vtmd.table->mark_columns_needed_for_update(); // not needed? if (archive_name) { - vtmd.table->s->versioned= false; + vtmd.table->vers_write= false; error= vtmd.table->file->ha_update_row(vtmd.table->record[1], vtmd.table->record[0]); - vtmd.table->s->versioned= true; + vtmd.table->vers_write= true; if (!error) { @@ -220,9 +220,9 @@ VTMD_table::update(THD *thd, const char* archive_name) store_record(vtmd.table, record[1]); vtmd.table->field[FLD_ARCHIVE_NAME]->store(archive_name, an_len, table_alias_charset); vtmd.table->field[FLD_ARCHIVE_NAME]->set_notnull(); - vtmd.table->s->versioned= false; + vtmd.table->vers_write= false; error= vtmd.table->file->ha_update_row(vtmd.table->record[1], vtmd.table->record[0]); - vtmd.table->s->versioned= true; + vtmd.table->vers_write= true; if (error) goto err; sys_trx_end= (ulonglong) vtmd.table->vers_start_field()->val_int(); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 402c2b5ed15..c8012d8c074 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -8369,7 +8369,7 @@ no_commit: innobase_srv_conc_enter_innodb(m_prebuilt); - vers_set_fields = (table->versioned() && + vers_set_fields = (table->versioned_write() && (sql_command != SQLCOM_CREATE_TABLE || table->s->vtmd)) ? ROW_INS_VERSIONED : @@ -9179,7 +9179,7 @@ ha_innobase::update_row( innobase_srv_conc_enter_innodb(m_prebuilt); - if (!table->versioned()) + if (!table->versioned_write()) m_prebuilt->upd_node->versioned = false; if (m_prebuilt->upd_node->versioned) { @@ -9317,7 +9317,7 @@ ha_innobase::delete_row( innobase_srv_conc_enter_innodb(m_prebuilt); bool vers_set_fields = - table->versioned() && + table->versioned_write() && table->vers_end_field()->is_max(); error = row_update_for_mysql(m_prebuilt, vers_set_fields); diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index d1516c21b81..40dcc96416c 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -2304,21 +2304,7 @@ end_of_index: } if (old_table->versioned()) { - if (new_table->versioned() && !drop_historical) { - dfield_t *end = dtuple_get_nth_field( - row, new_table->vers_end); - byte *data = static_cast<byte *>( - dfield_get_data(end)); - ut_ad(data); - if (mach_read_from_8(data) == TRX_ID_MAX) { - dfield_t *start = dtuple_get_nth_field( - row, new_table->vers_start); - void *data = dfield_get_data(start); - ut_ad(data); - mach_write_to_8(data, trx->id); - trx->vers_update_trt= true; - } - } else { + if (!new_table->versioned() || drop_historical) { const dict_col_t *col = &old_table->cols [old_table->vers_end]; |