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

dict_table_t::rollback_instant(): Roll back instant ADD COLUMN in the cache

parent 4a2ad0ce
......@@ -1131,3 +1131,47 @@ dict_mem_table_is_system(
return true;
}
}
/** Roll back the 'instant ADD' of some columns.
@param[in] n number of surviving non-system columns */
void dict_table_t::rollback_instant(unsigned n)
{
dict_index_t* index = indexes.start;
DBUG_ASSERT(index->is_instant());
DBUG_ASSERT(n > index->n_uniq);
DBUG_ASSERT(n_cols > n + DATA_N_SYS_COLS);
const unsigned n_remove = n_cols - n - DATA_N_SYS_COLS;
char* names = const_cast<char*>(dict_table_get_col_name(this, n));
const char* sys = names;
for (unsigned i = n_remove; i--; ) {
sys += strlen(sys) + 1;
}
static const char system[] = "DB_ROW_ID\0DB_TRX_ID\0DB_ROLL_PTR";
DBUG_ASSERT(!memcmp(sys, system, sizeof system));
for (unsigned i = index->n_fields - n_remove; i < index->n_fields;
i++) {
index->n_nullable -= index->fields[i].col->is_nullable();
}
index->n_fields -= n_remove;
memmove(names, sys, sizeof system);
memmove(cols + n, cols + n_cols - DATA_N_SYS_COLS,
DATA_N_SYS_COLS * sizeof *cols);
n_cols -= n_remove;
for (unsigned i = DATA_N_SYS_COLS; i--; ) {
cols[n_cols - i].ind--;
}
if (dict_index_is_auto_gen_clust(index)) {
DBUG_ASSERT(index->n_uniq == 1);
dict_field_t* field = index->fields;
field->name = sys;
field->col = dict_table_get_sys_col(this, DATA_ROW_ID);
}
dict_field_t* field = &index->fields[index->n_uniq];
field->name = sys + sizeof "DB_ROW_ID";
field->col = dict_table_get_sys_col(this, DATA_TRX_ID);
field++;
field->name = sys + sizeof "DB_ROW_ID\0DB_TRX_ID";
field->col = dict_table_get_sys_col(this, DATA_ROLL_PTR);
}
......@@ -1518,6 +1518,10 @@ struct dict_table_t {
return(!(flags & DICT_TF_MASK_ZIP_SSIZE));
}
/** Roll back the 'instant ADD' of some columns.
@param[in] n number of surviving non-system columns */
void rollback_instant(unsigned n);
/** Add the table definition to the data dictionary cache */
void add_to_cache();
......
......@@ -181,36 +181,7 @@ row_undo_ins_remove_clust_rec(
/* This is the rollback of an instant ADD COLUMN.
Remove the column from the dictionary cache,
but keep the system columns. */
char* names = const_cast<char*>(
dict_table_get_col_name(table, pos));
const char* sys = names + strlen(names) + 1;
static const char system[]
= "DB_ROW_ID\0DB_TRX_ID\0DB_ROLL_PTR";
ut_ad(!memcmp(sys, system, sizeof system));
index->n_nullable -= index->fields[--index->n_fields]
.col->is_nullable();
memmove(names, sys, sizeof system);
table->n_cols--;
memmove(table->cols + pos, table->cols + pos + 1,
DATA_N_SYS_COLS * sizeof *table->cols);
for (uint i = 3; i--; ) {
table->cols[table->n_cols - i].ind--;
}
if (dict_index_is_auto_gen_clust(index)) {
ut_ad(index->n_uniq == 1);
dict_field_t* field = index->fields;
field->name = sys;
field->col = dict_table_get_sys_col(
table, DATA_ROW_ID);
}
dict_field_t* field = &index->fields[index->n_uniq];
field->name = sys + sizeof "DB_ROW_ID";
field->col = dict_table_get_sys_col(table,
DATA_TRX_ID);
field++;
field->name = sys + sizeof "DB_ROW_ID\0DB_TRX_ID";
field->col = dict_table_get_sys_col(table,
DATA_ROLL_PTR);
table->rollback_instant(pos);
}
dict_table_close(table, true, false);
......
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