summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2017-10-05 10:00:44 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2017-10-05 10:00:44 +0300
commitdda1231169b0ce5ea0103023a7fd2a5fffbf4bbc (patch)
treeccb77dd1645310aaaf5fc1f1fd1b65c9bf930c48
parent4a2ad0ceb690d6c25c51e389dafd3e5419d6c4eb (diff)
downloadmariadb-git-dda1231169b0ce5ea0103023a7fd2a5fffbf4bbc.tar.gz
dict_table_t::rollback_instant(): Roll back instant ADD COLUMN in the cache
-rw-r--r--storage/innobase/dict/dict0mem.cc44
-rw-r--r--storage/innobase/include/dict0mem.h4
-rw-r--r--storage/innobase/row/row0uins.cc31
3 files changed, 49 insertions, 30 deletions
diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc
index 56150055f4a..46d7b572eb2 100644
--- a/storage/innobase/dict/dict0mem.cc
+++ b/storage/innobase/dict/dict0mem.cc
@@ -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);
+}
diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h
index 5ff65078e44..5144888a393 100644
--- a/storage/innobase/include/dict0mem.h
+++ b/storage/innobase/include/dict0mem.h
@@ -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();
diff --git a/storage/innobase/row/row0uins.cc b/storage/innobase/row/row0uins.cc
index 569d72df75a..6628007909e 100644
--- a/storage/innobase/row/row0uins.cc
+++ b/storage/innobase/row/row0uins.cc
@@ -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);