@@ -160,6 +160,73 @@ static void instant_metadata_lock(dict_index_t& index, mtr_t& mtr)
160
160
ut_ad (!buf_block_get_page_zip (btr_cur_get_block (&btr_cur)));
161
161
}
162
162
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
+
163
230
/* * Set is_instant() before instant_column().
164
231
@param[in] old previous table definition
165
232
@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,
364
431
mtr.commit ();
365
432
}
366
433
367
-
368
434
/* * Adjust index metadata for instant ADD/DROP/reorder COLUMN.
369
435
@param[in] clustered index definition after instant ALTER TABLE */
370
436
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,
553
619
index->instant_add_field (*dict_table_get_first_index (&table));
554
620
555
621
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));
560
622
/* FIXME: add instant->heap, and transfer ownership here */
561
623
if (!instant) {
562
624
instant = new (mem_heap_zalloc (heap, sizeof *instant))
@@ -575,38 +637,7 @@ inline void dict_table_t::instant_column(const dict_table_t& table,
575
637
* sizeof *instant->dropped );
576
638
}
577
639
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);
610
641
}
611
642
612
643
while ((index = dict_table_get_next_index (index)) != NULL ) {
0 commit comments