Commit 24773bf3 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-19606: dict_v_col_t: Encapsulate v_indexes

Remove the separate allocation and pointer indirection of
dict_v_col_t::v_indexes.
parent 0274ab1d
...@@ -2496,19 +2496,9 @@ dict_index_add_col( ...@@ -2496,19 +2496,9 @@ dict_index_add_col(
if (col->is_virtual()) { if (col->is_virtual()) {
dict_v_col_t* v_col = reinterpret_cast<dict_v_col_t*>(col); dict_v_col_t* v_col = reinterpret_cast<dict_v_col_t*>(col);
/* Register the index with the virtual column index list */
/* When v_col->v_indexes==NULL, v_col->n_v_indexes++;
ha_innobase::commit_inplace_alter_table(commit=true) v_col->v_indexes.push_front(dict_v_idx_t(index, index->n_def));
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));
}
col_name = dict_table_get_v_col_name_mysql( col_name = dict_table_get_v_col_name_mysql(
table, dict_col_get_no(col)); table, dict_col_get_no(col));
} else { } else {
......
...@@ -167,6 +167,9 @@ dict_mem_table_create( ...@@ -167,6 +167,9 @@ dict_mem_table_create(
mem_heap_alloc(heap, table->n_cols * sizeof(dict_col_t))); mem_heap_alloc(heap, table->n_cols * sizeof(dict_col_t)));
table->v_cols = static_cast<dict_v_col_t*>( table->v_cols = static_cast<dict_v_col_t*>(
mem_heap_alloc(heap, n_v_cols * sizeof(*table->v_cols))); 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 - /* true means that the stats latch will be enabled -
dict_table_stats_lock() will not be noop. */ dict_table_stats_lock() will not be noop. */
...@@ -227,7 +230,7 @@ dict_mem_table_free( ...@@ -227,7 +230,7 @@ dict_mem_table_free(
/* Clean up virtual index info structures that are registered /* Clean up virtual index info structures that are registered
with virtual columns */ with virtual columns */
for (ulint i = 0; i < table->n_v_def; i++) { 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); UT_DELETE(table->s_cols);
...@@ -409,7 +412,7 @@ dict_mem_table_add_v_col( ...@@ -409,7 +412,7 @@ dict_mem_table_add_v_col(
v_col->num_base = num_base; v_col->num_base = num_base;
/* Initialize the index list for virtual columns */ /* 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; v_col->n_v_indexes = 0;
return(v_col); return(v_col);
...@@ -857,7 +860,7 @@ dict_mem_fill_vcol_has_index( ...@@ -857,7 +860,7 @@ dict_mem_fill_vcol_has_index(
continue; continue;
} }
for (const auto& v_idx : *v_col->v_indexes) { for (const auto& v_idx : v_col->v_indexes) {
if (v_idx.index != index) { if (v_idx.index != index) {
continue; continue;
} }
......
...@@ -590,7 +590,7 @@ inline bool dict_table_t::instant_column(const dict_table_t& table, ...@@ -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++) { for (unsigned i = 0; i < n_v_def; i++) {
dict_v_col_t& v = v_cols[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.n_v_indexes = 0;
v.base_col = static_cast<dict_col_t**>( v.base_col = static_cast<dict_col_t**>(
mem_heap_dup(heap, v.base_col, mem_heap_dup(heap, v.base_col,
...@@ -699,7 +699,7 @@ inline bool dict_table_t::instant_column(const dict_table_t& table, ...@@ -699,7 +699,7 @@ inline bool dict_table_t::instant_column(const dict_table_t& table,
if (f.col->is_virtual()) { if (f.col->is_virtual()) {
dict_v_col_t* v_col = reinterpret_cast dict_v_col_t* v_col = reinterpret_cast
<dict_v_col_t*>(f.col); <dict_v_col_t*>(f.col);
v_col->v_indexes->push_front( v_col->v_indexes.push_front(
dict_v_idx_t(index, i)); dict_v_idx_t(index, i));
v_col->n_v_indexes++; v_col->n_v_indexes++;
} }
...@@ -776,7 +776,7 @@ inline void dict_table_t::rollback_instant( ...@@ -776,7 +776,7 @@ inline void dict_table_t::rollback_instant(
} }
for (unsigned i = n_v_cols; i--; ) { 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) 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 ...@@ -1030,7 +1030,7 @@ struct ha_innobase_inplace_ctx : public inplace_alter_handler_ctx
dict_mem_index_free(index); dict_mem_index_free(index);
} }
for (unsigned i = old_n_v_cols; i--; ) { 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) { if (instant_table->fts) {
fts_free(instant_table); fts_free(instant_table);
...@@ -4950,6 +4950,7 @@ prepare_inplace_add_virtual( ...@@ -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( ctx->add_vcol[j].m_col.prtype = dtype_form_prtype(
field_type, charset_no); field_type, charset_no);
...@@ -4966,8 +4967,6 @@ prepare_inplace_add_virtual( ...@@ -4966,8 +4967,6 @@ prepare_inplace_add_virtual(
ctx->add_vcol[j].v_pos = ctx->old_table->n_v_cols ctx->add_vcol[j].v_pos = ctx->old_table->n_v_cols
- ctx->num_to_drop_vcol + j; - 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; ctx->add_vcol[j].n_v_indexes = 0;
/* MDEV-17468: Do this on ctx->instant_table later */ /* MDEV-17468: Do this on ctx->instant_table later */
innodb_base_col_setup(ctx->old_table, field, &ctx->add_vcol[j]); innodb_base_col_setup(ctx->old_table, field, &ctx->add_vcol[j]);
...@@ -11180,7 +11179,7 @@ ha_innobase::commit_inplace_alter_table( ...@@ -11180,7 +11179,7 @@ ha_innobase::commit_inplace_alter_table(
dict_table_close(m_prebuilt->table, true, false); dict_table_close(m_prebuilt->table, true, false);
if (ctx0->is_instant()) { if (ctx0->is_instant()) {
for (unsigned i = ctx0->old_n_v_cols; i--; ) { 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<unsigned&>(ctx0->old_n_v_cols) = 0; const_cast<unsigned&>(ctx0->old_n_v_cols) = 0;
} }
......
...@@ -705,10 +705,6 @@ struct dict_v_idx_t { ...@@ -705,10 +705,6 @@ struct dict_v_idx_t {
: index(index), nth_field(nth_field) {} : index(index), nth_field(nth_field) {}
}; };
/** Index list to put in dict_v_col_t */
typedef std::forward_list<dict_v_idx_t, ut_allocator<dict_v_idx_t> >
dict_v_idx_list;
/** Data structure for a virtual column in a table */ /** Data structure for a virtual column in a table */
struct dict_v_col_t{ struct dict_v_col_t{
/** column structure */ /** column structure */
...@@ -726,31 +722,30 @@ struct dict_v_col_t{ ...@@ -726,31 +722,30 @@ struct dict_v_col_t{
/** number of indexes */ /** number of indexes */
unsigned n_v_indexes:12; unsigned n_v_indexes:12;
/** Virtual index list, and column position in the index, /** Virtual index list, and column position in the index */
the allocated memory is not from table->heap */ std::forward_list<dict_v_idx_t, ut_allocator<dict_v_idx_t> >
dict_v_idx_list* v_indexes; v_indexes;
/** Detach the column from an index. /** Detach the column from an index.
@param[in] index index to be detached from */ @param[in] index index to be detached from */
void detach(const dict_index_t& index) void detach(const dict_index_t& index)
{ {
ut_ad(!n_v_indexes || v_indexes);
if (!n_v_indexes) return; if (!n_v_indexes) return;
auto i = v_indexes->before_begin(); auto i = v_indexes.before_begin();
ut_d(unsigned n = 0); ut_d(unsigned n = 0);
do { do {
auto prev = i++; auto prev = i++;
if (i == v_indexes->end()) { if (i == v_indexes.end()) {
ut_ad(n == n_v_indexes); ut_ad(n == n_v_indexes);
return; return;
} }
ut_ad(++n <= n_v_indexes); ut_ad(++n <= n_v_indexes);
if (i->index == &index) { if (i->index == &index) {
v_indexes->erase_after(prev); v_indexes.erase_after(prev);
n_v_indexes--; n_v_indexes--;
return; return;
} }
} while (i != v_indexes->end()); } while (i != v_indexes.end());
} }
}; };
......
...@@ -259,7 +259,7 @@ trx_undo_log_v_idx( ...@@ -259,7 +259,7 @@ trx_undo_log_v_idx(
ptr += mach_write_compressed(ptr, n_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 += mach_write_compressed(
ptr, static_cast<ulint>(v_index.index->id)); ptr, static_cast<ulint>(v_index.index->id));
...@@ -1021,7 +1021,7 @@ trx_undo_page_report_modify( ...@@ -1021,7 +1021,7 @@ trx_undo_page_report_modify(
on them */ on them */
if (upd_fld_is_virtual_col(fld) if (upd_fld_is_virtual_col(fld)
&& dict_table_get_nth_v_col( && dict_table_get_nth_v_col(
table, pos)->v_indexes->empty()) { table, pos)->v_indexes.empty()) {
n_updated--; n_updated--;
} }
} }
...@@ -1062,7 +1062,7 @@ trx_undo_page_report_modify( ...@@ -1062,7 +1062,7 @@ trx_undo_page_report_modify(
an online alter table */ an online alter table */
if (dict_index_is_online_ddl(index) if (dict_index_is_online_ddl(index)
&& dict_table_get_nth_v_col( && dict_table_get_nth_v_col(
table, pos)->v_indexes->empty()) { table, pos)->v_indexes.empty()) {
continue; continue;
} }
......
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