MCPcopy Create free account
hub / github.com/MariaDB/server / fk_check_column_changes

Function fk_check_column_changes

sql/sql_table.cc:9703–9822  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9701*/
9702
9703static enum fk_column_change_type
9704fk_check_column_changes(THD *thd, const TABLE *table,
9705 Alter_info *alter_info,
9706 FOREIGN_KEY_INFO *fk,
9707 const char **bad_column_name,
9708 bool referenced=false)
9709{
9710 List<LEX_CSTRING> &fk_columns= referenced
9711 ? fk->referenced_fields
9712 : fk->foreign_fields;
9713 List_iterator_fast<LEX_CSTRING> column_it(fk_columns);
9714 LEX_CSTRING *column;
9715 int n_col= 0;
9716
9717 *bad_column_name= NULL;
9718 enum fk_column_change_type result= FK_COLUMN_NO_CHANGE;
9719 bool strict_mode= thd->is_strict_mode();
9720
9721 while ((column= column_it++))
9722 {
9723 Create_field *new_field= get_field_by_old_name(alter_info, *column);
9724
9725 if (new_field)
9726 {
9727 Field *old_field= new_field->field;
9728
9729 if (!old_field->field_name.streq(new_field->field_name))
9730 {
9731 /*
9732 Copy algorithm doesn't support proper renaming of columns in
9733 the foreign key yet. At the moment we lack API which will tell
9734 SE that foreign keys should be updated to use new name of column
9735 like it happens in case of in-place algorithm.
9736 */
9737 result= FK_COLUMN_RENAMED;
9738 goto func_exit;
9739 }
9740
9741 /*
9742 Field_{num|decimal}::is_equal evaluates to IS_EQUAL_NO where
9743 the new_field adds an AUTO_INCREMENT flag on a column due to a
9744 limitation in MyISAM/ARIA. For the purposes of FK determination
9745 it doesn't matter if AUTO_INCREMENT is there or not.
9746 */
9747 const uint flags= new_field->flags;
9748 new_field->flags&= ~AUTO_INCREMENT_FLAG;
9749 const bool equal_result= old_field->is_equal(*new_field);
9750 new_field->flags= flags;
9751 const bool old_field_not_null= old_field->flags & NOT_NULL_FLAG;
9752 const bool new_field_not_null= new_field->flags & NOT_NULL_FLAG;
9753
9754 if ((equal_result == IS_EQUAL_NO))
9755 {
9756 /*
9757 Column in a FK has changed significantly and it
9758 may break referential integrity.
9759 */
9760 result= FK_COLUMN_DATA_CHANGE;

Callers 1

Calls 5

get_field_by_old_nameFunction · 0.85
is_strict_modeMethod · 0.80
streqMethod · 0.45
is_equalMethod · 0.45
is_nullableMethod · 0.45

Tested by

no test coverage detected