diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 50369760a0a..a0277c46af5 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -2496,19 +2496,9 @@ dict_index_add_col( if (col->is_virtual()) { dict_v_col_t* v_col = reinterpret_cast(col); - - /* When v_col->v_indexes==NULL, - ha_innobase::commit_inplace_alter_table(commit=true) - will evict and reload the table definition, and - v_col->v_indexes will not be NULL for the new table. */ - if (v_col->v_indexes != NULL) { - /* Register the index with the virtual column index - list */ - v_col->n_v_indexes++; - v_col->v_indexes->push_front( - dict_v_idx_t(index, index->n_def)); - } - + /* Register the index with the virtual column index list */ + v_col->n_v_indexes++; + v_col->v_indexes.push_front(dict_v_idx_t(index, index->n_def)); col_name = dict_table_get_v_col_name_mysql( table, dict_col_get_no(col)); } else { diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index 3290c27060e..9b6f74f9a95 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -167,6 +167,9 @@ dict_mem_table_create( mem_heap_alloc(heap, table->n_cols * sizeof(dict_col_t))); table->v_cols = static_cast( mem_heap_alloc(heap, n_v_cols * sizeof(*table->v_cols))); + for (ulint i = n_v_cols; i--; ) { + new (&table->v_cols[i]) dict_v_col_t(); + } /* true means that the stats latch will be enabled - dict_table_stats_lock() will not be noop. */ @@ -227,7 +230,7 @@ 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++) { - UT_DELETE(dict_table_get_nth_v_col(table, i)->v_indexes); + dict_table_get_nth_v_col(table, i)->~dict_v_col_t(); } UT_DELETE(table->s_cols); @@ -409,7 +412,7 @@ dict_mem_table_add_v_col( v_col->num_base = num_base; /* Initialize the index list for virtual columns */ - v_col->v_indexes = UT_NEW_NOKEY(dict_v_idx_list()); + ut_ad(v_col->v_indexes.empty()); v_col->n_v_indexes = 0; return(v_col); @@ -857,7 +860,7 @@ dict_mem_fill_vcol_has_index( continue; } - for (const auto& v_idx : *v_col->v_indexes) { + for (const auto& v_idx : v_col->v_indexes) { if (v_idx.index != index) { continue; } diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index d54d0ade7dc..c30414fcf5c 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -590,7 +590,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()); + DBUG_ASSERT(v.v_indexes.empty()); v.n_v_indexes = 0; v.base_col = static_cast( mem_heap_dup(heap, v.base_col, @@ -699,7 +699,7 @@ dup_dropped: if (f.col->is_virtual()) { dict_v_col_t* v_col = reinterpret_cast (f.col); - v_col->v_indexes->push_front( + v_col->v_indexes.push_front( dict_v_idx_t(index, i)); v_col->n_v_indexes++; } @@ -776,7 +776,7 @@ inline void dict_table_t::rollback_instant( } for (unsigned i = n_v_cols; i--; ) { - UT_DELETE(v_cols[i].v_indexes); + v_cols[i].~dict_v_col_t(); } index->n_core_fields = (index->n_fields == index->n_core_fields) @@ -1030,7 +1030,7 @@ struct ha_innobase_inplace_ctx : public inplace_alter_handler_ctx dict_mem_index_free(index); } for (unsigned i = old_n_v_cols; i--; ) { - UT_DELETE(old_v_cols[i].v_indexes); + old_v_cols[i].~dict_v_col_t(); } if (instant_table->fts) { fts_free(instant_table); @@ -4950,6 +4950,7 @@ prepare_inplace_add_virtual( } } + new (&ctx->add_vcol[j]) dict_v_col_t(); ctx->add_vcol[j].m_col.prtype = dtype_form_prtype( field_type, charset_no); @@ -4966,8 +4967,6 @@ prepare_inplace_add_virtual( ctx->add_vcol[j].v_pos = ctx->old_table->n_v_cols - ctx->num_to_drop_vcol + j; - /* 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]); @@ -11180,7 +11179,7 @@ foreign_fail: dict_table_close(m_prebuilt->table, true, false); if (ctx0->is_instant()) { for (unsigned i = ctx0->old_n_v_cols; i--; ) { - UT_DELETE(ctx0->old_v_cols[i].v_indexes); + ctx0->old_v_cols[i].~dict_v_col_t(); } const_cast(ctx0->old_n_v_cols) = 0; } diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index 62aaa4741ad..18df6f80737 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -705,10 +705,6 @@ struct dict_v_idx_t { : index(index), nth_field(nth_field) {} }; -/** Index list to put in dict_v_col_t */ -typedef std::forward_list > -dict_v_idx_list; - /** Data structure for a virtual column in a table */ struct dict_v_col_t{ /** column structure */ @@ -726,31 +722,30 @@ struct dict_v_col_t{ /** number of indexes */ unsigned n_v_indexes:12; - /** Virtual index list, and column position in the index, - the allocated memory is not from table->heap */ - dict_v_idx_list* v_indexes; + /** Virtual index list, and column position in the index */ + std::forward_list > + v_indexes; /** Detach the column from an index. @param[in] index index to be detached from */ void detach(const dict_index_t& index) { - ut_ad(!n_v_indexes || v_indexes); if (!n_v_indexes) return; - auto i = v_indexes->before_begin(); + auto i = v_indexes.before_begin(); ut_d(unsigned n = 0); do { auto prev = i++; - if (i == v_indexes->end()) { + if (i == v_indexes.end()) { ut_ad(n == n_v_indexes); return; } ut_ad(++n <= n_v_indexes); if (i->index == &index) { - v_indexes->erase_after(prev); + v_indexes.erase_after(prev); n_v_indexes--; return; } - } while (i != v_indexes->end()); + } while (i != v_indexes.end()); } }; diff --git a/storage/innobase/trx/trx0rec.cc b/storage/innobase/trx/trx0rec.cc index 0b41bee616b..3be07e0d39d 100644 --- a/storage/innobase/trx/trx0rec.cc +++ b/storage/innobase/trx/trx0rec.cc @@ -259,7 +259,7 @@ trx_undo_log_v_idx( ptr += mach_write_compressed(ptr, n_idx); - for (const auto& v_index : *vcol->v_indexes) { + for (const auto& v_index : vcol->v_indexes) { ptr += mach_write_compressed( ptr, static_cast(v_index.index->id)); @@ -1021,7 +1021,7 @@ trx_undo_page_report_modify( on them */ if (upd_fld_is_virtual_col(fld) && dict_table_get_nth_v_col( - table, pos)->v_indexes->empty()) { + table, pos)->v_indexes.empty()) { n_updated--; } } @@ -1062,7 +1062,7 @@ trx_undo_page_report_modify( an online alter table */ if (dict_index_is_online_ddl(index) && dict_table_get_nth_v_col( - table, pos)->v_indexes->empty()) { + table, pos)->v_indexes.empty()) { continue; }