Skip to content

Commit

Permalink
MDEV-19606: Replace most std::list with std::forward_list
Browse files Browse the repository at this point in the history
C++11 defines the singly-linked std::forward_list. Prefer it to
the doubly-linked std::list in cases where we dot really need it.
Also, clean up some code.

dict_index_remove_from_v_col_list(): Remove.
Obsoleted by dict_index_t::detach_columns().

There is no std::forward_list::push_back(). Use push_front() instead.
The ordering does not really matter.

dict_v_col_t::n_v_indexes: Added. There is no std::forward_list::size(),
and trx_undo_log_v_idx() needs to know the size.

rtr_info_track_t::rtr_active: Encapsulate. There really was no justification
for the pointer indirection.
  • Loading branch information
dr-m committed May 28, 2019
1 parent 50e79f6 commit 0274ab1
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 150 deletions.
3 changes: 2 additions & 1 deletion storage/innobase/dict/dict0crea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,8 @@ dict_create_table_step(
ut_ad(node->col_no == v_col->v_pos);
dict_build_v_col_def_step(node);

if (node->base_col_no < v_col->num_base - 1) {
if (node->base_col_no
< unsigned{v_col->num_base} - 1) {
/* move on to next base column */
node->base_col_no++;
} else {
Expand Down
41 changes: 2 additions & 39 deletions storage/innobase/dict/dict0dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2147,44 +2147,6 @@ dict_index_too_big_for_tree(
return(FALSE);
}

/** Clears the virtual column's index list before index is
being freed.
@param[in] index Index being freed */
void dict_index_remove_from_v_col_list(dict_index_t* index)
{
/* Index is not completely formed */
if (!index->cached) {
return;
}
if (dict_index_has_virtual(index)) {
const dict_col_t* col;
const dict_v_col_t* vcol;

for (ulint i = 0; i < dict_index_get_n_fields(index); i++) {
col = dict_index_get_nth_col(index, i);
if (col->is_virtual()) {
vcol = reinterpret_cast<const dict_v_col_t*>(
col);
/* This could be NULL, when we do add
virtual column, add index together. We do not
need to track this virtual column's index */
if (vcol->v_indexes == NULL) {
continue;
}
dict_v_idx_list::iterator it;
for (it = vcol->v_indexes->begin();
it != vcol->v_indexes->end(); ++it) {
dict_v_idx_t v_index = *it;
if (v_index.index == index) {
vcol->v_indexes->erase(it);
break;
}
}
}
}
}
}

/** Adds an index to the dictionary cache, with possible indexing newly
added column.
@param[in] index index; NOTE! The index memory
Expand Down Expand Up @@ -2542,7 +2504,8 @@ dict_index_add_col(
if (v_col->v_indexes != NULL) {
/* Register the index with the virtual column index
list */
v_col->v_indexes->push_back(
v_col->n_v_indexes++;
v_col->v_indexes->push_front(
dict_v_idx_t(index, index->n_def));
}

Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/dict/dict0load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,7 @@ dict_load_virtual_one_col(
btr_pcur_open_on_user_rec(sys_virtual_index, tuple, PAGE_CUR_GE,
BTR_SEARCH_LEAF, &pcur, &mtr);

for (i = 0; i < v_col->num_base + skipped; i++) {
for (i = 0; i < unsigned{v_col->num_base} + skipped; i++) {
const char* err_msg;
ulint pos;

Expand Down
41 changes: 12 additions & 29 deletions storage/innobase/dict/dict0mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,15 +227,10 @@ dict_mem_table_free(
/* Clean up virtual index info structures that are registered
with virtual columns */
for (ulint i = 0; i < table->n_v_def; i++) {
dict_v_col_t* vcol
= dict_table_get_nth_v_col(table, i);

UT_DELETE(vcol->v_indexes);
UT_DELETE(dict_table_get_nth_v_col(table, i)->v_indexes);
}

if (table->s_cols != NULL) {
UT_DELETE(table->s_cols);
}
UT_DELETE(table->s_cols);

mem_heap_free(table->heap);
}
Expand Down Expand Up @@ -415,6 +410,7 @@ dict_mem_table_add_v_col(

/* Initialize the index list for virtual columns */
v_col->v_indexes = UT_NEW_NOKEY(dict_v_idx_list());
v_col->n_v_indexes = 0;

return(v_col);
}
Expand Down Expand Up @@ -448,7 +444,7 @@ dict_mem_table_add_s_col(
}

s_col.num_base = num_base;
table->s_cols->push_back(s_col);
table->s_cols->push_front(s_col);
}

/**********************************************************************//**
Expand Down Expand Up @@ -749,13 +745,11 @@ dict_mem_index_create(

if (type & DICT_SPATIAL) {
mutex_create(LATCH_ID_RTR_SSN_MUTEX, &index->rtr_ssn.mutex);
index->rtr_track = static_cast<rtr_info_track_t*>(
mem_heap_alloc(
heap,
sizeof(*index->rtr_track)));
index->rtr_track = new
(mem_heap_alloc(heap, sizeof *index->rtr_track))
rtr_info_track_t();
mutex_create(LATCH_ID_RTR_ACTIVE_MUTEX,
&index->rtr_track->rtr_active_mutex);
index->rtr_track->rtr_active = UT_NEW_NOKEY(rtr_info_active());
}

return(index);
Expand Down Expand Up @@ -863,11 +857,7 @@ dict_mem_fill_vcol_has_index(
continue;
}

dict_v_idx_list::iterator it;
for (it = v_col->v_indexes->begin();
it != v_col->v_indexes->end(); ++it) {
dict_v_idx_t v_idx = *it;

for (const auto& v_idx : *v_col->v_indexes) {
if (v_idx.index != index) {
continue;
}
Expand Down Expand Up @@ -940,7 +930,7 @@ dict_mem_fill_vcol_set_for_base_col(
continue;
}

for (ulint j = 0; j < v_col->num_base; j++) {
for (ulint j = 0; j < unsigned{v_col->num_base}; j++) {
if (strcmp(col_name, dict_table_get_col_name(
table,
v_col->base_col[j]->ind)) == 0) {
Expand Down Expand Up @@ -1064,22 +1054,15 @@ dict_mem_index_free(
dict_index_zip_pad_mutex_destroy(index);

if (dict_index_is_spatial(index)) {
rtr_info_active::iterator it;
rtr_info_t* rtr_info;

for (it = index->rtr_track->rtr_active->begin();
it != index->rtr_track->rtr_active->end(); ++it) {
rtr_info = *it;

for (auto& rtr_info : index->rtr_track->rtr_active) {
rtr_info->index = NULL;
}

mutex_destroy(&index->rtr_ssn.mutex);
mutex_destroy(&index->rtr_track->rtr_active_mutex);
UT_DELETE(index->rtr_track->rtr_active);
index->rtr_track->~rtr_info_track_t();
}

dict_index_remove_from_v_col_list(index);
index->detach_columns();
mem_heap_free(index->heap);
}

Expand Down
30 changes: 8 additions & 22 deletions storage/innobase/gis/gis0sea.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2016, 2018, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2018, MariaDB Corporation.
Copyright (c) 2017, 2019, 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 @@ -972,7 +972,7 @@ rtr_create_rtr_info(
&rtr_info->rtr_path_mutex);

mutex_enter(&index->rtr_track->rtr_active_mutex);
index->rtr_track->rtr_active->push_back(rtr_info);
index->rtr_track->rtr_active.push_front(rtr_info);
mutex_exit(&index->rtr_track->rtr_active_mutex);
return(rtr_info);
}
Expand Down Expand Up @@ -1045,7 +1045,7 @@ rtr_init_rtr_info(
rtr_info->index = index;

mutex_enter(&index->rtr_track->rtr_active_mutex);
index->rtr_track->rtr_active->push_back(rtr_info);
index->rtr_track->rtr_active.push_front(rtr_info);
mutex_exit(&index->rtr_track->rtr_active_mutex);
}

Expand Down Expand Up @@ -1097,7 +1097,7 @@ rtr_clean_rtr_info(
}

if (index) {
index->rtr_track->rtr_active->remove(rtr_info);
index->rtr_track->rtr_active.remove(rtr_info);
mutex_exit(&index->rtr_track->rtr_active_mutex);
}

Expand Down Expand Up @@ -1202,36 +1202,22 @@ rtr_check_discard_page(
the root page */
buf_block_t* block) /*!< in: block of page to be discarded */
{
ulint pageno = block->page.id.page_no();
rtr_info_t* rtr_info;
rtr_info_active::iterator it;
const ulint pageno = block->page.id.page_no();

mutex_enter(&index->rtr_track->rtr_active_mutex);

for (it = index->rtr_track->rtr_active->begin();
it != index->rtr_track->rtr_active->end(); ++it) {
rtr_info = *it;
rtr_node_path_t::iterator rit;
bool found = false;

for (const auto& rtr_info : index->rtr_track->rtr_active) {
if (cursor && rtr_info == cursor->rtr_info) {
continue;
}

mutex_enter(&rtr_info->rtr_path_mutex);
for (rit = rtr_info->path->begin();
rit != rtr_info->path->end(); ++rit) {
node_visit_t node = *rit;

for (const node_visit_t& node : *rtr_info->path) {
if (node.page_no == pageno) {
found = true;
rtr_rebuild_path(rtr_info, pageno);
break;
}
}

if (found) {
rtr_rebuild_path(rtr_info, pageno);
}
mutex_exit(&rtr_info->rtr_path_mutex);

if (rtr_info->matches) {
Expand Down
27 changes: 13 additions & 14 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5834,19 +5834,17 @@ innobase_build_v_templ(
const dict_v_col_t* vcol = dict_table_get_nth_v_col(
ib_table, i);

for (ulint j = 0; j < vcol->num_base; j++) {
ulint col_no = vcol->base_col[j]->ind;
marker[col_no] = true;
for (ulint j = vcol->num_base; j--; ) {
marker[vcol->base_col[j]->ind] = true;
}
}

if (add_v) {
for (ulint i = 0; i < add_v->n_v_col; i++) {
const dict_v_col_t* vcol = &add_v->v_col[i];

for (ulint j = 0; j < vcol->num_base; j++) {
ulint col_no = vcol->base_col[j]->ind;
marker[col_no] = true;
for (ulint j = vcol->num_base; j--; ) {
marker[vcol->base_col[j]->ind] = true;
}
}
}
Expand Down Expand Up @@ -11117,7 +11115,7 @@ create_table_info_t::create_table_def()
}

/** Fill base columns for the stored column present in the list. */
if (table->s_cols && table->s_cols->size()) {
if (table->s_cols && !table->s_cols->empty()) {
for (ulint i = 0; i < n_cols; i++) {
Field* field = m_form->field[i];

Expand Down Expand Up @@ -15104,7 +15102,8 @@ ha_innobase::get_cascade_foreign_key_table_list(
{
m_prebuilt->trx->op_info = "getting cascading foreign keys";

std::list<table_list_item, ut_allocator<table_list_item> > table_list;
std::forward_list<table_list_item, ut_allocator<table_list_item> >
table_list;

typedef std::set<st_handler_tablename, tablename_compare,
ut_allocator<st_handler_tablename> > cascade_fk_set;
Expand All @@ -15117,7 +15116,7 @@ ha_innobase::get_cascade_foreign_key_table_list(
struct table_list_item item = {m_prebuilt->table,
m_prebuilt->table->name.m_name};

table_list.push_back(item);
table_list.push_front(item);

/* Get the parent table, grand parent table info from the
table list by depth-first traversal. */
Expand All @@ -15126,8 +15125,8 @@ ha_innobase::get_cascade_foreign_key_table_list(
dict_table_t* parent = NULL;
std::pair<cascade_fk_set::iterator,bool> ret;

item = table_list.back();
table_list.pop_back();
item = table_list.front();
table_list.pop_front();
parent_table = item.table;

if (parent_table == NULL) {
Expand Down Expand Up @@ -15174,13 +15173,13 @@ ha_innobase::get_cascade_foreign_key_table_list(
foreign->referenced_table,
foreign->referenced_table_name_lookup};

table_list.push_back(item1);
table_list.push_front(item1);

st_handler_tablename* fk_table =
(st_handler_tablename*) thd_memdup(
thd, &f1, sizeof(*fk_table));

fk_table_list->push_back(fk_table);
fk_table_list->push_front(fk_table);
}
}

Expand Down Expand Up @@ -20680,7 +20679,7 @@ innobase_get_computed_value(
buf = rec_buf2;
}

for (ulint i = 0; i < col->num_base; i++) {
for (ulint i = 0; i < unsigned{col->num_base}; i++) {
dict_col_t* base_col = col->base_col[i];
const dfield_t* row_field = NULL;
ulint col_no = base_col->ind;
Expand Down
14 changes: 9 additions & 5 deletions storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ inline bool dict_table_t::instant_column(const dict_table_t& table,
for (unsigned i = 0; i < n_v_def; i++) {
dict_v_col_t& v = v_cols[i];
v.v_indexes = UT_NEW_NOKEY(dict_v_idx_list());
v.n_v_indexes = 0;
v.base_col = static_cast<dict_col_t**>(
mem_heap_dup(heap, v.base_col,
v.num_base * sizeof *v.base_col));
Expand Down Expand Up @@ -696,9 +697,11 @@ inline bool dict_table_t::instant_column(const dict_table_t& table,
}
f.name = f.col->name(*this);
if (f.col->is_virtual()) {
reinterpret_cast<dict_v_col_t*>(f.col)
->v_indexes->push_back(
dict_v_idx_t(index, i));
dict_v_col_t* v_col = reinterpret_cast
<dict_v_col_t*>(f.col);
v_col->v_indexes->push_front(
dict_v_idx_t(index, i));
v_col->n_v_indexes++;
}
}
}
Expand Down Expand Up @@ -4965,6 +4968,7 @@ prepare_inplace_add_virtual(

/* No need to track the list */
ctx->add_vcol[j].v_indexes = NULL;
ctx->add_vcol[j].n_v_indexes = 0;
/* MDEV-17468: Do this on ctx->instant_table later */
innodb_base_col_setup(ctx->old_table, field, &ctx->add_vcol[j]);
j++;
Expand Down Expand Up @@ -5206,7 +5210,7 @@ static bool innobase_add_one_virtual(
return true;
}

for (ulint i = 0; i < vcol->num_base; i++) {
for (ulint i = 0; i < unsigned{vcol->num_base}; i++) {
if (innobase_insert_sys_virtual(
table, pos, vcol->base_col[i]->ind, trx)) {
return true;
Expand Down Expand Up @@ -7395,7 +7399,7 @@ alter_fill_stored_column(

s_col.num_base = num_base;
innodb_base_col_setup_for_stored(table, field, &s_col);
(*s_cols)->push_back(s_col);
(*s_cols)->push_front(s_col);
}
}

Expand Down
4 changes: 0 additions & 4 deletions storage/innobase/include/dict0dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -992,10 +992,6 @@ dict_make_room_in_cache(
ulint max_tables, /*!< in: max tables allowed in cache */
ulint pct_check); /*!< in: max percent to check */

/** Clears the virtual column's index list before index is being freed.
@param[in] index Index being freed */
void dict_index_remove_from_v_col_list(dict_index_t* index);

/** Adds an index to the dictionary cache, with possible indexing newly
added column.
@param[in] index index; NOTE! The index memory
Expand Down
Loading

0 comments on commit 0274ab1

Please sign in to comment.