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(
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<doc_id_t>(fts_read_doc_id(
static_cast<const byte*>(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)
{
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<doc_id_t>(mach_read_from_8(data));
if (my_heap && !heap) {
mem_heap_free(my_heap);
}
return(doc_id);
const ulint* offsets)
{
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;
}
/*********************************************************************//**
......
/*****************************************************************************
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.
......
......@@ -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
......
......@@ -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);
}
}
......
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