Skip to content

Commit

Permalink
InnoDB: reduce size of dtuple_t
Browse files Browse the repository at this point in the history
Making a linked list of dtuple_t is needed only for inserting
records. It's better to store tuples in a non-intrusive
container to not affect all other use cases of dtuple_t

dtuple_t::tuple_list: removed, it was 2 * sizeof(void*) bytes

ins_node_t::entry_list: now it's std::vector<dtuple_t*>

ins_node_t::entry: now it's std::vector<dtuple_t*>::iterator

DBUG_EXECUTE_IF("row_ins_skip_sec": this dead code removed
  • Loading branch information
kevgs committed Mar 20, 2020
1 parent 54b2da9 commit 45973ec
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
6 changes: 2 additions & 4 deletions storage/innobase/include/data0data.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2019, MariaDB Corporation.
Copyright (c) 2017, 2019, 2020 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
Expand Down Expand Up @@ -32,6 +32,7 @@ Created 5/30/1994 Heikki Tuuri
#include "mem0mem.h"
#include "dict0types.h"
#include "btr0types.h"
#include <vector>

#include <ostream>

Expand Down Expand Up @@ -510,9 +511,6 @@ struct dtuple_t {
dfield_t* fields; /*!< fields */
ulint n_v_fields; /*!< number of virtual fields */
dfield_t* v_fields; /*!< fields on virtual column */
UT_LIST_NODE_T(dtuple_t) tuple_list;
/*!< data tuples can be linked into a
list using this field */
#ifdef UNIV_DEBUG
ulint magic_n; /*!< magic number, used in
debug assertions */
Expand Down
15 changes: 10 additions & 5 deletions storage/innobase/include/row0ins.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2019, MariaDB Corporation.
Copyright (c) 2017, 2019, 2020 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
Expand Down Expand Up @@ -31,6 +31,7 @@ Created 4/20/1996 Heikki Tuuri
#include "que0types.h"
#include "trx0types.h"
#include "row0types.h"
#include <vector>

/***************************************************************//**
Checks if foreign key constraint fails for an index entry. Sets shared locks
Expand Down Expand Up @@ -159,7 +160,10 @@ row_ins_step(
/* Insert node structure */

struct ins_node_t{
que_common_t common; /*!< node type: QUE_NODE_INSERT */
ins_node_t() : common(QUE_NODE_INSERT, NULL), entry(entry_list.end())
{
}
que_common_t common; /*!< node type: QUE_NODE_INSERT */
ulint ins_type;/* INS_VALUES, INS_SEARCHED, or INS_DIRECT */
dtuple_t* row; /*!< row to insert */
dict_table_t* table; /*!< table where to insert */
Expand All @@ -169,11 +173,12 @@ struct ins_node_t{
ulint state; /*!< node execution state */
dict_index_t* index; /*!< NULL, or the next index where the index
entry should be inserted */
dtuple_t* entry; /*!< NULL, or entry to insert in the index;
std::vector<dtuple_t*>
entry_list;/* list of entries, one for each index */
std::vector<dtuple_t*>::iterator
entry; /*!< NULL, or entry to insert in the index;
after a successful insert of the entry,
this should be reset to NULL */
UT_LIST_BASE_NODE_T(dtuple_t)
entry_list;/* list of entries, one for each index */
/** buffer for the system columns */
byte sys_buf[DATA_ROW_ID_LEN
+ DATA_TRX_ID_LEN + DATA_ROLL_PTR_LEN];
Expand Down
4 changes: 3 additions & 1 deletion storage/innobase/que/que0que.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2018, MariaDB Corporation.
Copyright (c) 2017, 2018, 2020 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
Expand Down Expand Up @@ -460,6 +460,8 @@ que_graph_free_recursive(
que_graph_free_recursive(ins->select);
ins->select = NULL;

ins->~ins_node_t();

if (ins->entry_sys_heap != NULL) {
mem_heap_free(ins->entry_sys_heap);
ins->entry_sys_heap = NULL;
Expand Down
38 changes: 18 additions & 20 deletions storage/innobase/row/row0ins.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2016, 2019, MariaDB Corporation.
Copyright (c) 2016, 2019, 2020 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
Expand Down Expand Up @@ -73,8 +73,8 @@ ins_node_create(
{
ins_node_t* node;

node = static_cast<ins_node_t*>(
mem_heap_alloc(heap, sizeof(ins_node_t)));
node = new (static_cast<ins_node_t*>(
mem_heap_alloc(heap, sizeof(ins_node_t)))) ins_node_t;

node->common.type = QUE_NODE_INSERT;

Expand All @@ -83,7 +83,6 @@ ins_node_create(
node->state = INS_NODE_SET_IX_LOCK;
node->table = table;
node->index = NULL;
node->entry = NULL;

node->select = NULL;

Expand All @@ -109,12 +108,12 @@ ins_node_create_entry_list(

ut_ad(node->entry_sys_heap);

UT_LIST_INIT(node->entry_list, &dtuple_t::tuple_list);

/* We will include all indexes (include those corrupted
secondary indexes) in the entry list. Filteration of
secondary indexes) in the entry list. Filtration of
these corrupted index will be done in row_ins() */

node->entry_list.reserve(UT_LIST_GET_LEN(node->table->indexes));

for (index = dict_table_get_first_index(node->table);
index != 0;
index = dict_table_get_next_index(index)) {
Expand All @@ -123,7 +122,7 @@ ins_node_create_entry_list(
node->row, NULL, index, node->entry_sys_heap,
ROW_BUILD_FOR_INSERT);

UT_LIST_ADD_LAST(node->entry_list, entry);
node->entry_list.push_back(entry);
}
}

Expand Down Expand Up @@ -189,7 +188,8 @@ ins_node_set_new_row(
{
node->state = INS_NODE_SET_IX_LOCK;
node->index = NULL;
node->entry = NULL;
node->entry_list.clear();
node->entry = node->entry_list.end();

node->row = row;

Expand Down Expand Up @@ -3413,15 +3413,16 @@ row_ins_index_entry_step(

ut_ad(dtuple_check_typed(node->row));

err = row_ins_index_entry_set_vals(node->index, node->entry, node->row);
err = row_ins_index_entry_set_vals(node->index, *node->entry,
node->row);

if (err != DB_SUCCESS) {
DBUG_RETURN(err);
}

ut_ad(dtuple_check_typed(node->entry));
ut_ad(dtuple_check_typed(*node->entry));

err = row_ins_index_entry(node->index, node->entry, thr);
err = row_ins_index_entry(node->index, *node->entry, thr);

DEBUG_SYNC_C_IF_THD(thr_get_trx(thr)->mysql_thd,
"after_row_ins_index_entry_step");
Expand Down Expand Up @@ -3539,7 +3540,8 @@ row_ins(
row_ins_alloc_row_id_step(node);

node->index = dict_table_get_first_index(node->table);
node->entry = UT_LIST_GET_FIRST(node->entry_list);
ut_ad(node->entry_list.empty() == false);
node->entry = node->entry_list.begin();

if (node->ins_type == INS_SEARCHED) {

Expand All @@ -3565,20 +3567,16 @@ row_ins(
}

node->index = dict_table_get_next_index(node->index);
node->entry = UT_LIST_GET_NEXT(tuple_list, node->entry);

DBUG_EXECUTE_IF(
"row_ins_skip_sec",
node->index = NULL; node->entry = NULL; break;);
++node->entry;

/* Skip corrupted secondary index and its entry */
while (node->index && node->index->is_corrupted()) {
node->index = dict_table_get_next_index(node->index);
node->entry = UT_LIST_GET_NEXT(tuple_list, node->entry);
++node->entry;
}
}

ut_ad(node->entry == NULL);
ut_ad(node->entry == node->entry_list.end());

node->state = INS_NODE_ALLOC_ROW_ID;

Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/row/row0mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ row_get_prebuilt_insert_row(
may need to rebuild the row insert template. */

if (prebuilt->trx_id == table->def_trx_id
&& UT_LIST_GET_LEN(prebuilt->ins_node->entry_list)
&& prebuilt->ins_node->entry_list.size()
== UT_LIST_GET_LEN(table->indexes)) {

return(prebuilt->ins_node->row);
Expand Down

0 comments on commit 45973ec

Please sign in to comment.