diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 3c372045e82..9b0cca3b644 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -3713,13 +3713,6 @@ fts_get_max_doc_id( if (!page_is_empty(btr_pcur_get_page(&pcur))) { const rec_t* rec = NULL; - ulint offsets_[REC_OFFS_NORMAL_SIZE]; - ulint* offsets = offsets_; - mem_heap_t* heap = NULL; - ulint len; - const void* data; - - rec_offs_init(offsets_); do { rec = btr_pcur_get_rec(&pcur); @@ -3729,18 +3722,11 @@ fts_get_max_doc_id( } } while (btr_pcur_move_to_prev(&pcur, &mtr)); - if (!rec) { + if (!rec || rec_is_metadata(rec, *index)) { goto func_exit; } - ut_ad(!rec_is_metadata(rec, *index)); - offsets = rec_get_offsets( - rec, index, offsets, true, ULINT_UNDEFINED, &heap); - - data = rec_get_nth_field(rec, offsets, 0, &len); - - doc_id = static_cast(fts_read_doc_id( - static_cast(data))); + doc_id = fts_read_doc_id(rec); } func_exit: @@ -5222,49 +5208,23 @@ fts_get_doc_id_from_row( } /** Extract the doc id from the record that belongs to index. -@param[in] table table -@param[in] rec record contains FTS_DOC_ID +@param[in] rec record containing FTS_DOC_ID @param[in] index index of rec -@param[in] heap heap memory +@param[in] offsets rec_get_offsets(rec,index) @return doc id that was extracted from rec */ doc_id_t fts_get_doc_id_from_rec( - dict_table_t* table, const rec_t* rec, const dict_index_t* index, - mem_heap_t* heap) + const ulint* offsets) { - ulint len; - const byte* data; - ulint col_no; - doc_id_t doc_id = 0; - ulint offsets_[REC_OFFS_NORMAL_SIZE]; - ulint* offsets = offsets_; - mem_heap_t* my_heap = heap; - - ut_a(table->fts->doc_col != ULINT_UNDEFINED); - - rec_offs_init(offsets_); - - offsets = rec_get_offsets( - rec, index, offsets, true, ULINT_UNDEFINED, &my_heap); - - col_no = dict_col_get_index_pos( - &table->cols[table->fts->doc_col], index); - - ut_ad(col_no != ULINT_UNDEFINED); - - data = rec_get_nth_field(rec, offsets, col_no, &len); - - ut_a(len == 8); - ut_ad(8 == sizeof(doc_id)); - doc_id = static_cast(mach_read_from_8(data)); - - if (my_heap && !heap) { - mem_heap_free(my_heap); - } - - return(doc_id); + ulint f = dict_col_get_index_pos( + &index->table->cols[index->table->fts->doc_col], index); + ulint len; + doc_id_t doc_id = mach_read_from_8( + rec_get_nth_field(rec, offsets, f, &len)); + ut_ad(len == 8); + return doc_id; } /*********************************************************************//** diff --git a/storage/innobase/include/fts0fts.h b/storage/innobase/include/fts0fts.h index 9a4805e6eba..3d63c1fb3ad 100644 --- a/storage/innobase/include/fts0fts.h +++ b/storage/innobase/include/fts0fts.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2011, 2018, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2016, 2017, MariaDB Corporation. +Copyright (c) 2016, 2018, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -614,17 +614,15 @@ fts_get_doc_id_from_row( want to extract.*/ /** Extract the doc id from the record that belongs to index. -@param[in] table table -@param[in] rec record contains FTS_DOC_ID +@param[in] rec record containing FTS_DOC_ID @param[in] index index of rec -@param[in] heap heap memory +@param[in] offsets rec_get_offsets(rec,index) @return doc id that was extracted from rec */ doc_id_t fts_get_doc_id_from_rec( - dict_table_t* table, - const rec_t* rec, - const dict_index_t* index, - mem_heap_t* heap); + const rec_t* rec, + const dict_index_t* index, + const ulint* offsets); /** Add new fts doc id to the update vector. @param[in] table the table that contains the FTS index. diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 1014168d389..4b3ada8e33f 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -1276,8 +1276,10 @@ row_ins_foreign_check_on_constraint( } if (table->fts) { - doc_id = fts_get_doc_id_from_rec(table, clust_rec, - clust_index, tmp_heap); + doc_id = fts_get_doc_id_from_rec( + clust_rec, clust_index, + rec_get_offsets(clust_rec, clust_index, NULL, true, + ULINT_UNDEFINED, &tmp_heap)); } if (node->is_delete diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index a8787574e5a..3cf9f57084f 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -3214,7 +3214,7 @@ row_sel_store_mysql_rec( if (dict_index_is_clust(index) || prebuilt->fts_doc_id_in_read_set) { prebuilt->fts_doc_id = fts_get_doc_id_from_rec( - prebuilt->table, rec, index, NULL); + rec, index, offsets); } }