Commit 3773bc59 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-17750: Avoid some rec_get_offsets() for accessing FTS_DOC_ID

fts_get_max_doc_id(): Remove totally unnecessary call to rec_get_offsets().
In FTS_DOC_ID_INDEX, the FTS_DOC_ID is always stored in the first 8 bytes
of the record.

fts_get_doc_id_from_row(): Get the offsets from the caller.

row_ins_foreign_check_on_constraint(): Invoke rec_get_offsets()
for the call.
parent 0cbf578a
...@@ -3713,13 +3713,6 @@ fts_get_max_doc_id( ...@@ -3713,13 +3713,6 @@ fts_get_max_doc_id(
if (!page_is_empty(btr_pcur_get_page(&pcur))) { if (!page_is_empty(btr_pcur_get_page(&pcur))) {
const rec_t* rec = NULL; 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 { do {
rec = btr_pcur_get_rec(&pcur); rec = btr_pcur_get_rec(&pcur);
...@@ -3729,18 +3722,11 @@ fts_get_max_doc_id( ...@@ -3729,18 +3722,11 @@ fts_get_max_doc_id(
} }
} while (btr_pcur_move_to_prev(&pcur, &mtr)); } while (btr_pcur_move_to_prev(&pcur, &mtr));
if (!rec) { if (!rec || rec_is_metadata(rec, *index)) {
goto func_exit; goto func_exit;
} }
ut_ad(!rec_is_metadata(rec, *index)); doc_id = fts_read_doc_id(rec);
offsets = rec_get_offsets(
rec, index, offsets, true, ULINT_UNDEFINED, &heap);
data = rec_get_nth_field(rec, offsets, 0, &len);
doc_id = static_cast<doc_id_t>(fts_read_doc_id(
static_cast<const byte*>(data)));
} }
func_exit: func_exit:
...@@ -5222,49 +5208,23 @@ fts_get_doc_id_from_row( ...@@ -5222,49 +5208,23 @@ fts_get_doc_id_from_row(
} }
/** Extract the doc id from the record that belongs to index. /** Extract the doc id from the record that belongs to index.
@param[in] table table @param[in] rec record containing FTS_DOC_ID
@param[in] rec record contains FTS_DOC_ID
@param[in] index index of rec @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 */ @return doc id that was extracted from rec */
doc_id_t doc_id_t
fts_get_doc_id_from_rec( fts_get_doc_id_from_rec(
dict_table_t* table,
const rec_t* rec, const rec_t* rec,
const dict_index_t* index, const dict_index_t* index,
mem_heap_t* heap) const ulint* offsets)
{ {
ulint len; ulint f = dict_col_get_index_pos(
const byte* data; &index->table->cols[index->table->fts->doc_col], index);
ulint col_no; ulint len;
doc_id_t doc_id = 0; doc_id_t doc_id = mach_read_from_8(
ulint offsets_[REC_OFFS_NORMAL_SIZE]; rec_get_nth_field(rec, offsets, f, &len));
ulint* offsets = offsets_; ut_ad(len == 8);
mem_heap_t* my_heap = heap; return doc_id;
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<doc_id_t>(mach_read_from_8(data));
if (my_heap && !heap) {
mem_heap_free(my_heap);
}
return(doc_id);
} }
/*********************************************************************//** /*********************************************************************//**
......
/***************************************************************************** /*****************************************************************************
Copyright (c) 2011, 2018, Oracle and/or its affiliates. All Rights Reserved. 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 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 the terms of the GNU General Public License as published by the Free Software
...@@ -614,17 +614,15 @@ fts_get_doc_id_from_row( ...@@ -614,17 +614,15 @@ fts_get_doc_id_from_row(
want to extract.*/ want to extract.*/
/** Extract the doc id from the record that belongs to index. /** Extract the doc id from the record that belongs to index.
@param[in] table table @param[in] rec record containing FTS_DOC_ID
@param[in] rec record contains FTS_DOC_ID
@param[in] index index of rec @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 */ @return doc id that was extracted from rec */
doc_id_t doc_id_t
fts_get_doc_id_from_rec( fts_get_doc_id_from_rec(
dict_table_t* table, const rec_t* rec,
const rec_t* rec, const dict_index_t* index,
const dict_index_t* index, const ulint* offsets);
mem_heap_t* heap);
/** Add new fts doc id to the update vector. /** Add new fts doc id to the update vector.
@param[in] table the table that contains the FTS index. @param[in] table the table that contains the FTS index.
......
...@@ -1276,8 +1276,10 @@ row_ins_foreign_check_on_constraint( ...@@ -1276,8 +1276,10 @@ row_ins_foreign_check_on_constraint(
} }
if (table->fts) { if (table->fts) {
doc_id = fts_get_doc_id_from_rec(table, clust_rec, doc_id = fts_get_doc_id_from_rec(
clust_index, tmp_heap); clust_rec, clust_index,
rec_get_offsets(clust_rec, clust_index, NULL, true,
ULINT_UNDEFINED, &tmp_heap));
} }
if (node->is_delete if (node->is_delete
......
...@@ -3214,7 +3214,7 @@ row_sel_store_mysql_rec( ...@@ -3214,7 +3214,7 @@ row_sel_store_mysql_rec(
if (dict_index_is_clust(index) if (dict_index_is_clust(index)
|| prebuilt->fts_doc_id_in_read_set) { || prebuilt->fts_doc_id_in_read_set) {
prebuilt->fts_doc_id = fts_get_doc_id_from_rec( prebuilt->fts_doc_id = fts_get_doc_id_from_rec(
prebuilt->table, rec, index, NULL); rec, index, offsets);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment