diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index 4d21f90fa97..f5f61eff5b3 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -1216,10 +1216,10 @@ inline void dict_index_t::reconstruct_fields() n_nullable = 0; ulint n_core_null = 0; const bool comp = dict_table_is_comp(table); - const unsigned* non_pk_col_map = table->instant->non_pk_col_map; + const auto* non_pk_col_map = table->instant->non_pk_col_map; for (unsigned i = n_first, o = i, j = 0; i < n_fields; ) { dict_field_t& f = tfields[i++]; - unsigned c = *non_pk_col_map++; + auto c = *non_pk_col_map++; if (c & 1U << 15) { f.col = &table->instant->dropped[j++]; ut_ad(f.col->is_dropped()); @@ -1241,32 +1241,6 @@ inline void dict_index_t::reconstruct_fields() n_core_null_bytes = UT_BITS_IN_BYTES(n_core_null); } -/** Serialise metadata of dropped or reordered columns. -@param[in,out] heap memory heap for allocation -@param[out] field data field with the metadata */ -void dict_table_t::serialise_columns(mem_heap_t* heap, dfield_t* field) const -{ - DBUG_ASSERT(instant); - const dict_index_t& index = *UT_LIST_GET_FIRST(indexes); - unsigned n_fixed = index.first_user_field(); - unsigned num_non_pk_fields = index.n_fields - n_fixed; - - ulint len = 4 + num_non_pk_fields * 2; - - byte* data = static_cast(mem_heap_alloc(heap, len)); - - dfield_set_data(field, data, len); - - mach_write_to_4(data, num_non_pk_fields); - - data += 4; - - for (ulint i = n_fixed; i < index.n_fields; i++) { - mach_write_to_2(data, instant->non_pk_col_map[i - n_fixed]); - data += 2; - } -} - /** Reconstruct dropped or reordered columns. @param[in] metadata data from serialise_columns() @param[in] len length of the metadata, in bytes @@ -1289,7 +1263,7 @@ bool dict_table_t::deserialise_columns(const byte* metadata, ulint len) return true; } - unsigned* non_pk_col_map = static_cast( + uint16_t* non_pk_col_map = static_cast( mem_heap_alloc(heap, num_non_pk_fields * sizeof *non_pk_col_map)); @@ -1320,7 +1294,7 @@ bool dict_table_t::deserialise_columns(const byte* metadata, ulint len) dict_col_t* col = dropped_cols; for (unsigned i = 0; i < num_non_pk_fields; i++) { if (non_pk_col_map[i] & 1U << 15) { - unsigned fixed_len = non_pk_col_map[i] & ~(3U << 14); + auto fixed_len = non_pk_col_map[i] & ~(3U << 14); DBUG_ASSERT(fixed_len <= DICT_MAX_FIXED_COL_LEN + 1); (col++)->set_dropped(non_pk_col_map[i] & 1U << 14, fixed_len == 1, diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index f0e31545154..fdfb9192cfd 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -487,7 +487,7 @@ inline void dict_table_t::instant_column(const dict_table_t& table, if (instant || table.instant) { const unsigned u = index->first_user_field(); - unsigned* non_pk_col_map = static_cast( + uint16_t* non_pk_col_map = static_cast( mem_heap_alloc(heap, (index->n_fields - u) * sizeof *non_pk_col_map)); /* FIXME: add instant->heap, and transfer ownership here */ @@ -524,9 +524,9 @@ dup_dropped: ulint fixed_len = dict_col_get_fixed_size( field->col, flags & DICT_TF_COMPACT); *non_pk_col_map++ = 1U << 15 - | unsigned(!field->col->is_nullable()) << 14 + | uint16_t(!field->col->is_nullable()) << 14 | (fixed_len - ? unsigned(fixed_len + 1) + ? uint16_t(fixed_len + 1) : field->col->len > 255); ut_ad(field->col >= table.instant->dropped); ut_ad(field->col < table.instant->dropped @@ -5110,6 +5110,33 @@ innobase_drop_virtual_try( return false; } +/** Serialise metadata of dropped or reordered columns. +@param[in,out] heap memory heap for allocation +@param[out] field data field with the metadata */ +inline +void dict_table_t::serialise_columns(mem_heap_t* heap, dfield_t* field) const +{ + DBUG_ASSERT(instant); + const dict_index_t& index = *UT_LIST_GET_FIRST(indexes); + unsigned n_fixed = index.first_user_field(); + unsigned num_non_pk_fields = index.n_fields - n_fixed; + + ulint len = 4 + num_non_pk_fields * 2; + + byte* data = static_cast(mem_heap_alloc(heap, len)); + + dfield_set_data(field, data, len); + + mach_write_to_4(data, num_non_pk_fields); + + data += 4; + + for (ulint i = n_fixed; i < index.n_fields; i++) { + mach_write_to_2(data, instant->non_pk_col_map[i - n_fixed]); + data += 2; + } +} + /** Construct the metadata record for instant ALTER TABLE. @param[in] row dummy or default values for existing columns @param[in,out] heap memory heap for allocations diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index b4823ee6a94..1521fb74970 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -1513,7 +1513,7 @@ struct dict_instant_t /** Dropped columns */ dict_col_t* dropped; /** Mapping the non-pk field to column of the table. */ - unsigned* non_pk_col_map; + uint16_t* non_pk_col_map; }; /** These are used when MySQL FRM and InnoDB data dictionary are @@ -1606,7 +1606,7 @@ struct dict_table_t { /** Serialise metadata of dropped or reordered columns. @param[in,out] heap memory heap for allocation @param[out] field data field with the metadata */ - void serialise_columns(mem_heap_t* heap, dfield_t* field) const; + inline void serialise_columns(mem_heap_t* heap, dfield_t* field) const; /** Reconstruct dropped or reordered columns. @param[in] metadata data from serialise_columns()