Skip to content

Commit a044e32

Browse files
committed
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.
1 parent b32a319 commit a044e32

File tree

2 files changed

+76
-37
lines changed

2 files changed

+76
-37
lines changed

storage/innobase/handler/handler0alter.cc

Lines changed: 68 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,73 @@ static void instant_metadata_lock(dict_index_t& index, mtr_t& mtr)
160160
ut_ad(!buf_block_get_page_zip(btr_cur_get_block(&btr_cur)));
161161
}
162162

163+
/** Initialize instant->non_pk_col_map.
164+
@tparam replace_dropped whether to point clustered index fields
165+
to instant->dropped[]
166+
@param[in] table table definition to copy from */
167+
template<bool replace_dropped>
168+
inline void dict_table_t::init_instant(const dict_table_t& table)
169+
{
170+
const dict_index_t& oindex = *table.indexes.start;
171+
dict_index_t& index = *indexes.start;
172+
const unsigned u = index.first_user_field();
173+
DBUG_ASSERT(u == oindex.first_user_field());
174+
DBUG_ASSERT(not_redundant() == table.not_redundant());
175+
DBUG_ASSERT(index.n_fields >= oindex.n_fields);
176+
177+
uint16_t* non_pk_col_map = static_cast<uint16_t*>(
178+
mem_heap_zalloc(heap, (index.n_fields - u)
179+
* sizeof *non_pk_col_map));
180+
instant->non_pk_col_map = non_pk_col_map;
181+
182+
ut_d(unsigned n_drop = 0);
183+
ut_d(unsigned n_nullable = 0);
184+
for (unsigned i = u; i < index.n_fields; i++) {
185+
auto& f = index.fields[i];
186+
DBUG_ASSERT(dict_col_get_fixed_size(f.col, not_redundant())
187+
<= DICT_MAX_FIXED_COL_LEN);
188+
#ifdef UNIV_DEBUG
189+
if (!f.col->is_nullable()) {
190+
ut_ad((*non_pk_col_map & 3U << 15) != 1U << 14);
191+
} else if ((*non_pk_col_map & 3U << 15) != 1U << 14) {
192+
n_nullable++;
193+
}
194+
#endif
195+
if (!f.col->is_dropped()) {
196+
auto c = *non_pk_col_map & 3U << 14;
197+
DBUG_ASSERT(!(c & 1U << 15));
198+
if (!c
199+
&& f.col->is_nullable()
200+
&& !oindex.fields[i].col->is_nullable()) {
201+
c = 1U << 14;
202+
}
203+
*non_pk_col_map++ = c | f.col->ind;
204+
continue;
205+
}
206+
207+
auto fixed_len = dict_col_get_fixed_size(
208+
f.col, not_redundant());
209+
*non_pk_col_map++ = 1U << 15
210+
| uint16_t(!f.col->is_nullable()) << 14
211+
| (fixed_len
212+
? uint16_t(fixed_len + 1)
213+
: f.col->len > 255);
214+
ut_ad(f.col >= table.instant->dropped);
215+
ut_ad(f.col < table.instant->dropped
216+
+ table.instant->n_dropped);
217+
ut_d(n_drop++);
218+
if (replace_dropped) {
219+
size_t d = f.col - table.instant->dropped;
220+
ut_ad(f.col == &table.instant->dropped[d]);
221+
ut_ad(d <= instant->n_dropped);
222+
f.col = &instant->dropped[d];
223+
}
224+
}
225+
ut_ad(n_drop == n_dropped());
226+
ut_ad(non_pk_col_map == &instant->non_pk_col_map[index.n_fields - u]);
227+
ut_ad(index.n_nullable == n_nullable);
228+
}
229+
163230
/** Set is_instant() before instant_column().
164231
@param[in] old previous table definition
165232
@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,
364431
mtr.commit();
365432
}
366433

367-
368434
/** Adjust index metadata for instant ADD/DROP/reorder COLUMN.
369435
@param[in] clustered index definition after instant ALTER TABLE */
370436
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,
553619
index->instant_add_field(*dict_table_get_first_index(&table));
554620

555621
if (instant || table.instant) {
556-
const unsigned u = index->first_user_field();
557-
uint16_t* non_pk_col_map = static_cast<uint16_t*>(
558-
mem_heap_alloc(heap, (index->n_fields - u)
559-
* sizeof *non_pk_col_map));
560622
/* FIXME: add instant->heap, and transfer ownership here */
561623
if (!instant) {
562624
instant = new (mem_heap_zalloc(heap, sizeof *instant))
@@ -575,38 +637,7 @@ inline void dict_table_t::instant_column(const dict_table_t& table,
575637
* sizeof *instant->dropped);
576638
}
577639

578-
instant->non_pk_col_map = non_pk_col_map;
579-
ut_d(unsigned n_drop = 0);
580-
for (unsigned i = u; i < index->n_fields; i++) {
581-
dict_field_t* field = &index->fields[i];
582-
DBUG_ASSERT(dict_col_get_fixed_size(
583-
field->col,
584-
flags & DICT_TF_COMPACT)
585-
<= DICT_MAX_FIXED_COL_LEN);
586-
if (!field->col->is_dropped()) {
587-
*non_pk_col_map++ = field->col->ind;
588-
continue;
589-
}
590-
591-
ulint fixed_len = dict_col_get_fixed_size(
592-
field->col, flags & DICT_TF_COMPACT);
593-
*non_pk_col_map++ = 1U << 15
594-
| uint16_t(!field->col->is_nullable()) << 14
595-
| (fixed_len
596-
? uint16_t(fixed_len + 1)
597-
: field->col->len > 255);
598-
ut_ad(field->col >= table.instant->dropped);
599-
ut_ad(field->col < table.instant->dropped
600-
+ table.instant->n_dropped);
601-
ut_d(n_drop++);
602-
size_t d = field->col - table.instant->dropped;
603-
ut_ad(field->col == &table.instant->dropped[d]);
604-
ut_ad(d <= instant->n_dropped);
605-
field->col = &instant->dropped[d];
606-
}
607-
ut_ad(n_drop == n_dropped());
608-
ut_ad(non_pk_col_map
609-
== &instant->non_pk_col_map[index->n_fields - u]);
640+
init_instant<true>(table);
610641
}
611642

612643
while ((index = dict_table_get_next_index(index)) != NULL) {

storage/innobase/include/dict0mem.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,14 @@ struct dict_table_t {
17161716
ut_ad(fk_checks > 0);
17171717
}
17181718

1719+
private:
1720+
/** Initialize instant->non_pk_col_map.
1721+
@tparam replace_dropped whether to point clustered index fields
1722+
to instant->dropped[]
1723+
@param[in] table table definition to copy from */
1724+
template<bool replace_dropped = false>
1725+
inline void init_instant(const dict_table_t& table);
1726+
public:
17191727
/** Id of the table. */
17201728
table_id_t id;
17211729

0 commit comments

Comments
 (0)