diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index cdfc8b3ee19..132e7960541 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -1474,3 +1474,73 @@ void dict_table_t::rollback_instant(unsigned n) field->name = sys + sizeof "DB_ROW_ID\0DB_TRX_ID"; field->col = dict_table_get_sys_col(this, DATA_ROLL_PTR); } + + +/** Check if record in clustered index is historical row. +@param[in] rec clustered row +@param[in] offsets offsets +@return true if row is historical */ +bool +dict_index_t::vers_history_row( + const rec_t* rec, + const ulint* offsets) +{ + ut_a(is_clust()); + + ulint len; + dict_col_t& col= table->cols[table->vers_end]; + ut_ad(col.vers_sys_end()); + ulint nfield = dict_col_get_clust_pos(&col, this); + const byte *data = rec_get_nth_field(rec, offsets, nfield, &len); + if (col.mtype == DATA_FIXBINARY) { + ut_ad(len == sizeof timestamp_max_bytes); + return 0 != memcmp(data, timestamp_max_bytes, len); + } else { + ut_ad(col.mtype == DATA_INT); + ut_ad(len == sizeof trx_id_max_bytes); + return 0 != memcmp(data, trx_id_max_bytes, len); + } + ut_ad(0); + return false; +} + +/** Check if record in secondary index is historical row. +@param[in] rec record in a secondary index +@param[out] history_row true if row is historical +@return true on error */ +bool +dict_index_t::vers_history_row( + const rec_t* rec, + bool &history_row) +{ + ut_ad(!is_clust()); + + bool error = false; + mem_heap_t* heap = NULL; + dict_index_t* clust_index = NULL; + ulint offsets_[REC_OFFS_NORMAL_SIZE]; + ulint* offsets = offsets_; + rec_offs_init(offsets_); + + mtr_t mtr; + mtr.start(); + + rec_t* clust_rec = + row_get_clust_rec(BTR_SEARCH_LEAF, rec, this, &clust_index, &mtr); + if (clust_rec) { + offsets = rec_get_offsets(clust_rec, clust_index, offsets, true, + ULINT_UNDEFINED, &heap); + + history_row = clust_index->vers_history_row(clust_rec, offsets); + } else { + ib::error() << "foreign constraints: secondary index is out of " + "sync"; + ut_ad(!"secondary index is out of sync"); + error = true; + } + mtr.commit(); + if (heap) { + mem_heap_free(heap); + } + return(error); +} diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 0a76bca9e48..8ec96f530df 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -1568,75 +1568,6 @@ private: ulint& counter; }; -/** Check if record in clustered index is historical row. -@param[in] rec clustered row -@param[in] offsets offsets -@return true if row is historical */ -bool -dict_index_t::vers_history_row( - const rec_t* rec, - const ulint* offsets) -{ - ut_a(is_clust()); - - ulint len; - dict_col_t& col= table->cols[table->vers_end]; - ut_ad(col.vers_sys_end()); - ulint nfield = dict_col_get_clust_pos(&col, this); - const byte *data = rec_get_nth_field(rec, offsets, nfield, &len); - if (col.mtype == DATA_FIXBINARY) { - ut_ad(len == sizeof timestamp_max_bytes); - return 0 != memcmp(data, timestamp_max_bytes, len); - } else { - ut_ad(col.mtype == DATA_INT); - ut_ad(len == sizeof trx_id_max_bytes); - return 0 != memcmp(data, trx_id_max_bytes, len); - } - ut_ad(0); - return false; -} - -/** Check if record in secondary index is historical row. -@param[in] rec record in a secondary index -@param[out] history_row true if row is historical -@return true on error */ -bool -dict_index_t::vers_history_row( - const rec_t* rec, - bool &history_row) -{ - ut_ad(!is_clust()); - - bool error = false; - mem_heap_t* heap = NULL; - dict_index_t* clust_index = NULL; - ulint offsets_[REC_OFFS_NORMAL_SIZE]; - ulint* offsets = offsets_; - rec_offs_init(offsets_); - - mtr_t mtr; - mtr.start(); - - rec_t* clust_rec = - row_get_clust_rec(BTR_SEARCH_LEAF, rec, this, &clust_index, &mtr); - if (clust_rec) { - offsets = rec_get_offsets(clust_rec, clust_index, offsets, true, - ULINT_UNDEFINED, &heap); - - history_row = clust_index->vers_history_row(clust_rec, offsets); - } else { - ib::error() << "foreign constraints: secondary index is out of " - "sync"; - ut_ad(!"secondary index is out of sync"); - error = true; - } - mtr.commit(); - if (heap) { - mem_heap_free(heap); - } - return(error); -} - /***************************************************************//** Checks if foreign key constraint fails for an index entry. Sets shared locks which lock either the success or the failure of the constraint. NOTE that