1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-13508 ALTER TABLE that renames columns and CHECK constraints

Fixed by adding Item::rename_fields_processor

Signed-off-by: Monty <monty@mariadb.org>
This commit is contained in:
Monty
2018-02-10 14:24:15 +02:00
parent 7beaa5e34e
commit 12d5307e95
9 changed files with 133 additions and 10 deletions

View File

@ -7558,6 +7558,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
List<Virtual_column_info> new_constraint_list;
uint db_create_options= (table->s->db_create_options
& ~(HA_OPTION_PACK_RECORD));
Item::func_processor_rename column_rename_param;
uint used_fields;
KEY *key_info=table->key_info;
bool rc= TRUE;
@ -7607,6 +7608,13 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
if (!(used_fields & HA_CREATE_USED_CONNECTION))
create_info->connect_string= table->s->connect_string;
column_rename_param.db_name.str= table->s->db.str;
column_rename_param.db_name.length= table->s->db.length;
column_rename_param.table_name.str= table->s->table_name.str;
column_rename_param.table_name.length= table->s->table_name.length;
if (column_rename_param.fields.copy(&alter_info->create_list, thd->mem_root))
DBUG_RETURN(1); // OOM
restore_record(table, s->default_values); // Empty record for DEFAULT
if ((create_info->fields_option_struct= (ha_field_option_struct**)
@ -7651,6 +7659,24 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
bitmap_set_bit(dropped_fields, field->field_index);
continue;
}
/*
If we are doing a rename of a column, update all references in virtual
column expressions, constraints and defaults to use the new column name
*/
if (alter_info->flags & Alter_info::ALTER_RENAME_COLUMN)
{
if (field->vcol_info)
field->vcol_info->expr->walk(&Item::rename_fields_processor, 1,
&column_rename_param);
if (field->check_constraint)
field->check_constraint->expr->walk(&Item::rename_fields_processor, 1,
&column_rename_param);
if (field->default_value)
field->default_value->expr->walk(&Item::rename_fields_processor, 1,
&column_rename_param);
}
/* Check if field is changed */
def_it.rewind();
while ((def=def_it++))
@ -8060,7 +8086,10 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
}
}
if (!drop)
{
check->expr->walk(&Item::rename_fields_processor, 1, &column_rename_param);
new_constraint_list.push_back(check, thd->mem_root);
}
}
}
/* Add new constraints */