Commit a044e326 authored by Marko Mäkelä's avatar Marko Mäkelä

Introduce dict_table_t::init_instant()

dict_table_t::init_instant(): Initialize instant->non_pk_col_map[].
Refactored from dict_table_t::instant_column().
Also, assert that the n_nullable for the clustered index is initialized
correctly.
parent b32a3191
......@@ -160,6 +160,73 @@ static void instant_metadata_lock(dict_index_t& index, mtr_t& mtr)
ut_ad(!buf_block_get_page_zip(btr_cur_get_block(&btr_cur)));
}
/** Initialize instant->non_pk_col_map.
@tparam replace_dropped whether to point clustered index fields
to instant->dropped[]
@param[in] table table definition to copy from */
template<bool replace_dropped>
inline void dict_table_t::init_instant(const dict_table_t& table)
{
const dict_index_t& oindex = *table.indexes.start;
dict_index_t& index = *indexes.start;
const unsigned u = index.first_user_field();
DBUG_ASSERT(u == oindex.first_user_field());
DBUG_ASSERT(not_redundant() == table.not_redundant());
DBUG_ASSERT(index.n_fields >= oindex.n_fields);
uint16_t* non_pk_col_map = static_cast<uint16_t*>(
mem_heap_zalloc(heap, (index.n_fields - u)
* sizeof *non_pk_col_map));
instant->non_pk_col_map = non_pk_col_map;
ut_d(unsigned n_drop = 0);
ut_d(unsigned n_nullable = 0);
for (unsigned i = u; i < index.n_fields; i++) {
auto& f = index.fields[i];
DBUG_ASSERT(dict_col_get_fixed_size(f.col, not_redundant())
<= DICT_MAX_FIXED_COL_LEN);
#ifdef UNIV_DEBUG
if (!f.col->is_nullable()) {
ut_ad((*non_pk_col_map & 3U << 15) != 1U << 14);
} else if ((*non_pk_col_map & 3U << 15) != 1U << 14) {
n_nullable++;
}
#endif
if (!f.col->is_dropped()) {
auto c = *non_pk_col_map & 3U << 14;
DBUG_ASSERT(!(c & 1U << 15));
if (!c
&& f.col->is_nullable()
&& !oindex.fields[i].col->is_nullable()) {
c = 1U << 14;
}
*non_pk_col_map++ = c | f.col->ind;
continue;
}
auto fixed_len = dict_col_get_fixed_size(
f.col, not_redundant());
*non_pk_col_map++ = 1U << 15
| uint16_t(!f.col->is_nullable()) << 14
| (fixed_len
? uint16_t(fixed_len + 1)
: f.col->len > 255);
ut_ad(f.col >= table.instant->dropped);
ut_ad(f.col < table.instant->dropped
+ table.instant->n_dropped);
ut_d(n_drop++);
if (replace_dropped) {
size_t d = f.col - table.instant->dropped;
ut_ad(f.col == &table.instant->dropped[d]);
ut_ad(d <= instant->n_dropped);
f.col = &instant->dropped[d];
}
}
ut_ad(n_drop == n_dropped());
ut_ad(non_pk_col_map == &instant->non_pk_col_map[index.n_fields - u]);
ut_ad(index.n_nullable == n_nullable);
}
/** Set is_instant() before instant_column().
@param[in] old previous table definition
@param[in] col_map map from old.cols[] and old.v_cols[] to this
......@@ -364,7 +431,6 @@ inline void dict_table_t::prepare_instant(const dict_table_t& old,
mtr.commit();
}
/** Adjust index metadata for instant ADD/DROP/reorder COLUMN.
@param[in] clustered index definition after instant ALTER TABLE */
inline void dict_index_t::instant_add_field(const dict_index_t& instant)
......@@ -553,10 +619,6 @@ inline void dict_table_t::instant_column(const dict_table_t& table,
index->instant_add_field(*dict_table_get_first_index(&table));
if (instant || table.instant) {
const unsigned u = index->first_user_field();
uint16_t* non_pk_col_map = static_cast<uint16_t*>(
mem_heap_alloc(heap, (index->n_fields - u)
* sizeof *non_pk_col_map));
/* FIXME: add instant->heap, and transfer ownership here */
if (!instant) {
instant = new (mem_heap_zalloc(heap, sizeof *instant))
......@@ -575,38 +637,7 @@ inline void dict_table_t::instant_column(const dict_table_t& table,
* sizeof *instant->dropped);
}
instant->non_pk_col_map = non_pk_col_map;
ut_d(unsigned n_drop = 0);
for (unsigned i = u; i < index->n_fields; i++) {
dict_field_t* field = &index->fields[i];
DBUG_ASSERT(dict_col_get_fixed_size(
field->col,
flags & DICT_TF_COMPACT)
<= DICT_MAX_FIXED_COL_LEN);
if (!field->col->is_dropped()) {
*non_pk_col_map++ = field->col->ind;
continue;
}
ulint fixed_len = dict_col_get_fixed_size(
field->col, flags & DICT_TF_COMPACT);
*non_pk_col_map++ = 1U << 15
| uint16_t(!field->col->is_nullable()) << 14
| (fixed_len
? uint16_t(fixed_len + 1)
: field->col->len > 255);
ut_ad(field->col >= table.instant->dropped);
ut_ad(field->col < table.instant->dropped
+ table.instant->n_dropped);
ut_d(n_drop++);
size_t d = field->col - table.instant->dropped;
ut_ad(field->col == &table.instant->dropped[d]);
ut_ad(d <= instant->n_dropped);
field->col = &instant->dropped[d];
}
ut_ad(n_drop == n_dropped());
ut_ad(non_pk_col_map
== &instant->non_pk_col_map[index->n_fields - u]);
init_instant<true>(table);
}
while ((index = dict_table_get_next_index(index)) != NULL) {
......
......@@ -1716,6 +1716,14 @@ struct dict_table_t {
ut_ad(fk_checks > 0);
}
private:
/** Initialize instant->non_pk_col_map.
@tparam replace_dropped whether to point clustered index fields
to instant->dropped[]
@param[in] table table definition to copy from */
template<bool replace_dropped = false>
inline void init_instant(const dict_table_t& table);
public:
/** Id of the table. */
table_id_t id;
......
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