Skip to content

Commit 172cc70

Browse files
committed
MDEV-13446 fts_create_doc_id() unnecessarily allocates 8 bytes for every inserted row
fts_create_doc_id(): Remove. row_mysql_convert_row_to_innobase(): Implement the logic of fts_create_doc_id(). Reuse a buffer for the hidden FTS_DOC_ID. row_get_prebuilt_insert_row(): Allocate a buffer for the hidden FTS_DOC_ID at the end of prebuilt->ins_upd_rec_buff.
1 parent bc85d22 commit 172cc70

File tree

6 files changed

+62
-136
lines changed

6 files changed

+62
-136
lines changed

storage/innobase/fts/fts0fts.cc

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2011, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2016, MariaDB Corporation. All Rights reserved.
4+
Copyright (c) 2016, 2017, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -3032,53 +3032,6 @@ fts_modify(
30323032
return(error);
30333033
}
30343034

3035-
/*********************************************************************//**
3036-
Create a new document id.
3037-
@return DB_SUCCESS if all went well else error */
3038-
UNIV_INTERN
3039-
dberr_t
3040-
fts_create_doc_id(
3041-
/*==============*/
3042-
dict_table_t* table, /*!< in: row is of this table. */
3043-
dtuple_t* row, /* in/out: add doc id value to this
3044-
row. This is the current row that is
3045-
being inserted. */
3046-
mem_heap_t* heap) /*!< in: heap */
3047-
{
3048-
doc_id_t doc_id;
3049-
dberr_t error = DB_SUCCESS;
3050-
3051-
ut_a(table->fts->doc_col != ULINT_UNDEFINED);
3052-
3053-
if (!DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID)) {
3054-
if (table->fts->cache->first_doc_id == FTS_NULL_DOC_ID) {
3055-
error = fts_get_next_doc_id(table, &doc_id);
3056-
}
3057-
return(error);
3058-
}
3059-
3060-
error = fts_get_next_doc_id(table, &doc_id);
3061-
3062-
if (error == DB_SUCCESS) {
3063-
dfield_t* dfield;
3064-
doc_id_t* write_doc_id;
3065-
3066-
ut_a(doc_id > 0);
3067-
3068-
dfield = dtuple_get_nth_field(row, table->fts->doc_col);
3069-
write_doc_id = static_cast<doc_id_t*>(
3070-
mem_heap_alloc(heap, sizeof(*write_doc_id)));
3071-
3072-
ut_a(doc_id != FTS_NULL_DOC_ID);
3073-
ut_a(sizeof(doc_id) == dfield->type.len);
3074-
fts_write_doc_id((byte*) write_doc_id, doc_id);
3075-
3076-
dfield_set_data(dfield, write_doc_id, sizeof(*write_doc_id));
3077-
}
3078-
3079-
return(error);
3080-
}
3081-
30823035
/*********************************************************************//**
30833036
The given transaction is about to be committed; do whatever is necessary
30843037
from the FTS system's POV.

storage/innobase/include/fts0fts.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2011, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2016, MariaDB Corporation. All Rights reserved.
4+
Copyright (c) 2016, 2017, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -429,21 +429,6 @@ fts_update_next_doc_id(
429429
MY_ATTRIBUTE((nonnull(2)));
430430

431431
/******************************************************************//**
432-
Create a new document id .
433-
@return DB_SUCCESS if all went well else error */
434-
UNIV_INTERN
435-
dberr_t
436-
fts_create_doc_id(
437-
/*==============*/
438-
dict_table_t* table, /*!< in: row is of this
439-
table. */
440-
dtuple_t* row, /*!< in/out: add doc id
441-
value to this row. This is the
442-
current row that is being
443-
inserted. */
444-
mem_heap_t* heap) /*!< in: heap */
445-
MY_ATTRIBUTE((nonnull));
446-
/******************************************************************//**
447432
Create a new fts_doc_ids_t.
448433
@return new fts_doc_ids_t. */
449434
UNIV_INTERN

storage/innobase/row/row0mysql.cc

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,33 @@ row_mysql_convert_row_to_innobase(
568568

569569
/* If there is a FTS doc id column and it is not user supplied (
570570
generated by server) then assign it a new doc id. */
571-
if (prebuilt->table->fts) {
571+
if (!prebuilt->table->fts) {
572+
return;
573+
}
574+
575+
ut_a(prebuilt->table->fts->doc_col != ULINT_UNDEFINED);
572576

573-
ut_a(prebuilt->table->fts->doc_col != ULINT_UNDEFINED);
577+
doc_id_t doc_id;
574578

575-
fts_create_doc_id(prebuilt->table, row, prebuilt->heap);
579+
if (!DICT_TF2_FLAG_IS_SET(prebuilt->table, DICT_TF2_FTS_HAS_DOC_ID)) {
580+
if (prebuilt->table->fts->cache->first_doc_id
581+
== FTS_NULL_DOC_ID) {
582+
fts_get_next_doc_id(prebuilt->table, &doc_id);
583+
}
584+
return;
585+
}
586+
587+
dfield_t* fts_doc_id = dtuple_get_nth_field(
588+
row, prebuilt->table->fts->doc_col);
589+
590+
if (fts_get_next_doc_id(prebuilt->table, &doc_id) == DB_SUCCESS) {
591+
ut_a(doc_id != FTS_NULL_DOC_ID);
592+
ut_ad(sizeof(doc_id) == fts_doc_id->type.len);
593+
dfield_set_data(fts_doc_id, prebuilt->ins_upd_rec_buff
594+
+ prebuilt->mysql_row_len, 8);
595+
fts_write_doc_id(fts_doc_id->data, doc_id);
596+
} else {
597+
dfield_set_null(fts_doc_id);
576598
}
577599
}
578600

@@ -1046,7 +1068,10 @@ row_get_prebuilt_insert_row(
10461068
prebuilt->ins_upd_rec_buff = static_cast<byte*>(
10471069
mem_heap_alloc(
10481070
prebuilt->heap,
1049-
prebuilt->mysql_row_len));
1071+
DICT_TF2_FLAG_IS_SET(prebuilt->table,
1072+
DICT_TF2_FTS_HAS_DOC_ID)
1073+
? prebuilt->mysql_row_len + 8/* FTS_DOC_ID */
1074+
: prebuilt->mysql_row_len));
10501075
}
10511076

10521077
dtuple_t* row;

storage/xtradb/fts/fts0fts.cc

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2011, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2016, MariaDB Corporation. All Rights reserved.
4+
Copyright (c) 2016, 2017, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -3032,53 +3032,6 @@ fts_modify(
30323032
return(error);
30333033
}
30343034

3035-
/*********************************************************************//**
3036-
Create a new document id.
3037-
@return DB_SUCCESS if all went well else error */
3038-
UNIV_INTERN
3039-
dberr_t
3040-
fts_create_doc_id(
3041-
/*==============*/
3042-
dict_table_t* table, /*!< in: row is of this table. */
3043-
dtuple_t* row, /* in/out: add doc id value to this
3044-
row. This is the current row that is
3045-
being inserted. */
3046-
mem_heap_t* heap) /*!< in: heap */
3047-
{
3048-
doc_id_t doc_id;
3049-
dberr_t error = DB_SUCCESS;
3050-
3051-
ut_a(table->fts->doc_col != ULINT_UNDEFINED);
3052-
3053-
if (!DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID)) {
3054-
if (table->fts->cache->first_doc_id == FTS_NULL_DOC_ID) {
3055-
error = fts_get_next_doc_id(table, &doc_id);
3056-
}
3057-
return(error);
3058-
}
3059-
3060-
error = fts_get_next_doc_id(table, &doc_id);
3061-
3062-
if (error == DB_SUCCESS) {
3063-
dfield_t* dfield;
3064-
doc_id_t* write_doc_id;
3065-
3066-
ut_a(doc_id > 0);
3067-
3068-
dfield = dtuple_get_nth_field(row, table->fts->doc_col);
3069-
write_doc_id = static_cast<doc_id_t*>(
3070-
mem_heap_alloc(heap, sizeof(*write_doc_id)));
3071-
3072-
ut_a(doc_id != FTS_NULL_DOC_ID);
3073-
ut_a(sizeof(doc_id) == dfield->type.len);
3074-
fts_write_doc_id((byte*) write_doc_id, doc_id);
3075-
3076-
dfield_set_data(dfield, write_doc_id, sizeof(*write_doc_id));
3077-
}
3078-
3079-
return(error);
3080-
}
3081-
30823035
/*********************************************************************//**
30833036
The given transaction is about to be committed; do whatever is necessary
30843037
from the FTS system's POV.

storage/xtradb/include/fts0fts.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2011, 2016, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2016, MariaDB Corporation. All Rights reserved.
4+
Copyright (c) 2016, 2017, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -429,21 +429,6 @@ fts_update_next_doc_id(
429429
MY_ATTRIBUTE((nonnull(2)));
430430

431431
/******************************************************************//**
432-
Create a new document id .
433-
@return DB_SUCCESS if all went well else error */
434-
UNIV_INTERN
435-
dberr_t
436-
fts_create_doc_id(
437-
/*==============*/
438-
dict_table_t* table, /*!< in: row is of this
439-
table. */
440-
dtuple_t* row, /*!< in/out: add doc id
441-
value to this row. This is the
442-
current row that is being
443-
inserted. */
444-
mem_heap_t* heap) /*!< in: heap */
445-
MY_ATTRIBUTE((nonnull));
446-
/******************************************************************//**
447432
Create a new fts_doc_ids_t.
448433
@return new fts_doc_ids_t. */
449434
UNIV_INTERN

storage/xtradb/row/row0mysql.cc

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,33 @@ row_mysql_convert_row_to_innobase(
567567

568568
/* If there is a FTS doc id column and it is not user supplied (
569569
generated by server) then assign it a new doc id. */
570-
if (prebuilt->table->fts) {
570+
if (!prebuilt->table->fts) {
571+
return;
572+
}
573+
574+
ut_a(prebuilt->table->fts->doc_col != ULINT_UNDEFINED);
571575

572-
ut_a(prebuilt->table->fts->doc_col != ULINT_UNDEFINED);
576+
doc_id_t doc_id;
573577

574-
fts_create_doc_id(prebuilt->table, row, prebuilt->heap);
578+
if (!DICT_TF2_FLAG_IS_SET(prebuilt->table, DICT_TF2_FTS_HAS_DOC_ID)) {
579+
if (prebuilt->table->fts->cache->first_doc_id
580+
== FTS_NULL_DOC_ID) {
581+
fts_get_next_doc_id(prebuilt->table, &doc_id);
582+
}
583+
return;
584+
}
585+
586+
dfield_t* fts_doc_id = dtuple_get_nth_field(
587+
row, prebuilt->table->fts->doc_col);
588+
589+
if (fts_get_next_doc_id(prebuilt->table, &doc_id) == DB_SUCCESS) {
590+
ut_a(doc_id != FTS_NULL_DOC_ID);
591+
ut_ad(sizeof(doc_id) == fts_doc_id->type.len);
592+
dfield_set_data(fts_doc_id, prebuilt->ins_upd_rec_buff
593+
+ prebuilt->mysql_row_len, 8);
594+
fts_write_doc_id(fts_doc_id->data, doc_id);
595+
} else {
596+
dfield_set_null(fts_doc_id);
575597
}
576598
}
577599

@@ -1045,7 +1067,10 @@ row_get_prebuilt_insert_row(
10451067
prebuilt->ins_upd_rec_buff = static_cast<byte*>(
10461068
mem_heap_alloc(
10471069
prebuilt->heap,
1048-
prebuilt->mysql_row_len));
1070+
DICT_TF2_FLAG_IS_SET(prebuilt->table,
1071+
DICT_TF2_FTS_HAS_DOC_ID)
1072+
? prebuilt->mysql_row_len + 8/* FTS_DOC_ID */
1073+
: prebuilt->mysql_row_len));
10491074
}
10501075

10511076
dtuple_t* row;

0 commit comments

Comments
 (0)