summaryrefslogtreecommitdiff
path: root/storage/xtradb/handler/handler0alter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'storage/xtradb/handler/handler0alter.cc')
-rw-r--r--storage/xtradb/handler/handler0alter.cc42
1 files changed, 35 insertions, 7 deletions
diff --git a/storage/xtradb/handler/handler0alter.cc b/storage/xtradb/handler/handler0alter.cc
index a6ec6e5465f..439c92b0638 100644
--- a/storage/xtradb/handler/handler0alter.cc
+++ b/storage/xtradb/handler/handler0alter.cc
@@ -129,6 +129,7 @@ my_error_innodb(
break;
case DB_OUT_OF_FILE_SPACE:
my_error(ER_RECORD_FILE_FULL, MYF(0), table);
+ ut_error;
break;
case DB_TEMP_FILE_WRITE_FAILURE:
my_error(ER_GET_ERRMSG, MYF(0),
@@ -1458,8 +1459,9 @@ innobase_create_index_field_def(
if a new clustered index is
not being created */
const KEY_PART_INFO* key_part, /*!< in: MySQL key definition */
- index_field_t* index_field) /*!< out: index field
+ index_field_t* index_field, /*!< out: index field
definition for key_part */
+ const Field** fields) /*!< in: MySQL table fields */
{
const Field* field;
ibool is_unsigned;
@@ -1476,6 +1478,7 @@ innobase_create_index_field_def(
ut_a(field);
index_field->col_no = key_part->fieldnr;
+ index_field->col_name = altered_table ? field->field_name : fields[key_part->fieldnr]->field_name;
col_type = get_innobase_type_from_mysql_type(&is_unsigned, field);
@@ -1510,8 +1513,9 @@ innobase_create_index_def(
bool key_clustered, /*!< in: true if this is
the new clustered index */
index_def_t* index, /*!< out: index definition */
- mem_heap_t* heap) /*!< in: heap where memory
+ mem_heap_t* heap, /*!< in: heap where memory
is allocated */
+ const Field** fields) /*!z in: MySQL table fields */
{
const KEY* key = &keys[key_number];
ulint i;
@@ -1525,6 +1529,8 @@ innobase_create_index_def(
index->fields = static_cast<index_field_t*>(
mem_heap_alloc(heap, n_fields * sizeof *index->fields));
+ memset(index->fields, 0, n_fields * sizeof *index->fields);
+
index->ind_type = 0;
index->key_number = key_number;
index->n_fields = n_fields;
@@ -1561,7 +1567,7 @@ innobase_create_index_def(
for (i = 0; i < n_fields; i++) {
innobase_create_index_field_def(
- altered_table, &key->key_part[i], &index->fields[i]);
+ altered_table, &key->key_part[i], &index->fields[i], fields);
}
DBUG_VOID_RETURN;
@@ -1892,7 +1898,7 @@ innobase_create_key_defs(
/* Create the PRIMARY key index definition */
innobase_create_index_def(
altered_table, key_info, primary_key_number,
- TRUE, TRUE, indexdef++, heap);
+ TRUE, TRUE, indexdef++, heap, (const Field **)altered_table->field);
created_clustered:
n_add = 1;
@@ -1904,7 +1910,7 @@ created_clustered:
/* Copy the index definitions. */
innobase_create_index_def(
altered_table, key_info, i, TRUE, FALSE,
- indexdef, heap);
+ indexdef, heap, (const Field **)altered_table->field);
if (indexdef->ind_type & DICT_FTS) {
n_fts_add++;
@@ -1949,7 +1955,7 @@ created_clustered:
for (ulint i = 0; i < n_add; i++) {
innobase_create_index_def(
altered_table, key_info, add[i], FALSE, FALSE,
- indexdef, heap);
+ indexdef, heap, (const Field **)altered_table->field);
if (indexdef->ind_type & DICT_FTS) {
n_fts_add++;
@@ -1966,6 +1972,7 @@ created_clustered:
index->fields = static_cast<index_field_t*>(
mem_heap_alloc(heap, sizeof *index->fields));
+ memset(index->fields, 0, sizeof *index->fields);
index->n_fields = 1;
index->fields->col_no = fts_doc_id_col;
index->fields->prefix_len = 0;
@@ -2821,7 +2828,7 @@ prepare_inplace_alter_table_dict(
/* The initial space id 0 may be overridden later. */
ctx->new_table = dict_mem_table_create(
- new_table_name, 0, n_cols, flags, flags2, false);
+ new_table_name, 0, n_cols, flags, flags2);
/* The rebuilt indexed_table will use the renamed
column names. */
ctx->col_names = NULL;
@@ -4479,11 +4486,15 @@ err_exit:
rename_foreign:
trx->op_info = "renaming column in SYS_FOREIGN_COLS";
+ std::list<dict_foreign_t*> fk_evict;
+ bool foreign_modified;
+
for (dict_foreign_set::const_iterator it = user_table->foreign_set.begin();
it != user_table->foreign_set.end();
++it) {
dict_foreign_t* foreign = *it;
+ foreign_modified = false;
for (unsigned i = 0; i < foreign->n_fields; i++) {
if (strcmp(foreign->foreign_col_names[i], from)) {
@@ -4511,6 +4522,11 @@ rename_foreign:
if (error != DB_SUCCESS) {
goto err_exit;
}
+ foreign_modified = true;
+ }
+
+ if (foreign_modified) {
+ fk_evict.push_back(foreign);
}
}
@@ -4519,7 +4535,9 @@ rename_foreign:
it != user_table->referenced_set.end();
++it) {
+ foreign_modified = false;
dict_foreign_t* foreign = *it;
+
for (unsigned i = 0; i < foreign->n_fields; i++) {
if (strcmp(foreign->referenced_col_names[i], from)) {
continue;
@@ -4546,7 +4564,17 @@ rename_foreign:
if (error != DB_SUCCESS) {
goto err_exit;
}
+ foreign_modified = true;
}
+
+ if (foreign_modified) {
+ fk_evict.push_back(foreign);
+ }
+ }
+
+ if (new_clustered) {
+ std::for_each(fk_evict.begin(), fk_evict.end(),
+ dict_foreign_remove_from_cache);
}
trx->op_info = "";