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

Fix dict_index_t::clear_instant_alter()

dict_index_t::clear_instant_alter(): Move the fields for the
dropped columns to the end, and sort the surviving index fields
in ascending order of column position.
parent c70aa163
...@@ -2098,6 +2098,7 @@ inline void dict_index_t::clear_instant_add() ...@@ -2098,6 +2098,7 @@ inline void dict_index_t::clear_instant_add()
inline void dict_index_t::clear_instant_alter() inline void dict_index_t::clear_instant_alter()
{ {
DBUG_ASSERT(is_primary()); DBUG_ASSERT(is_primary());
DBUG_ASSERT(n_fields == n_def);
if (!table->instant) { if (!table->instant) {
if (is_instant()) { if (is_instant()) {
...@@ -2106,36 +2107,41 @@ inline void dict_index_t::clear_instant_alter() ...@@ -2106,36 +2107,41 @@ inline void dict_index_t::clear_instant_alter()
return; return;
} }
const unsigned n_dropped = table->n_dropped(); #ifndef DBUG_OFF
for (unsigned i = first_user_field(); i--; ) {
unsigned old_n_fields = n_fields; DBUG_ASSERT(!fields[i].col->is_dropped());
n_fields -= n_dropped; DBUG_ASSERT(!fields[i].col->is_nullable());
n_def -= n_dropped; }
#endif
unsigned n_null = 0; dict_field_t* end = &fields[n_fields];
unsigned new_field = 0; dict_field_t* d = &fields[first_user_field()];
dict_field_t* temp_fields = static_cast<dict_field_t*>(
mem_heap_alloc(heap, n_fields * sizeof *temp_fields)); for (; d + 1 < end; d++) {
/* Move fields for dropped columns to the end. */
for (unsigned i = 0; i < old_n_fields; i++) { while (d->col->is_dropped()) {
dict_field_t field = fields[i]; if (d->col->is_nullable()) {
n_nullable--;
}
if (field.col->is_dropped()) { std::swap(*d, *--end);
continue;
} }
dict_field_t& f = temp_fields[new_field++]; /* Ensure that the surviving fields are sorted by
f = field; ascending order of columns. */
f.col->clear_instant(); const unsigned c = d->col->ind;
n_null += f.col->is_nullable(); for (dict_field_t* s = d + 1; s < end; s++) {
if (s->col->ind < c) {
std::swap(*d, *s);
break;
}
}
} }
ut_ad(n_fields == new_field); DBUG_ASSERT(&fields[n_fields - table->n_dropped()] == end);
fields = temp_fields;
n_core_fields = n_fields; n_core_fields = n_fields = n_def = end - fields;
n_nullable = n_null; n_core_null_bytes = UT_BITS_IN_BYTES(n_nullable);
n_core_null_bytes = UT_BITS_IN_BYTES(n_null);
table->instant = NULL; table->instant = NULL;
} }
......
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