Commit dec90f5b authored by unknown's avatar unknown

InnoDB: Ignore character set mismatch in ALTER TABLE and RENAME TABLE

if foreign_key_checks=0. (Bug #9802)


innobase/dict/dict0dict.c:
  dict_foreign_add_to_cache(): Add flag check_types.
  If the flag is FALSE, ignore character set mismatch.
innobase/dict/dict0load.c:
  dict_load_foreign(), dict_load_foreigns(): Add flag check_types.
  If the flag is FALSE, differences in character sets will be ignored.
innobase/include/dict0dict.h:
  dict_foreign_add_to_cache(): Add flag check_types.
  If the flag is FALSE, differences in character sets will be ignored.
innobase/include/dict0load.h:
  dict_load_foreigns(): Add flag check_types.
  If the flag is FALSE, differences in character sets will be ignored.
innobase/row/row0mysql.c:
  row_table_add_foreign_constraints(), row_rename_table_for_mysql():
  Pass trx->check_foreigns to dict_load_foreigns()
sql/ha_innodb.cc:
  ha_innobase::rename_table(): Clear trx->check_foreign if necessary.
parent 3fcbdd76
...@@ -2167,7 +2167,8 @@ ulint ...@@ -2167,7 +2167,8 @@ ulint
dict_foreign_add_to_cache( dict_foreign_add_to_cache(
/*======================*/ /*======================*/
/* out: DB_SUCCESS or error code */ /* out: DB_SUCCESS or error code */
dict_foreign_t* foreign) /* in, own: foreign key constraint */ dict_foreign_t* foreign, /* in, own: foreign key constraint */
ibool check_types) /* in: TRUE=check type compatibility */
{ {
dict_table_t* for_table; dict_table_t* for_table;
dict_table_t* ref_table; dict_table_t* ref_table;
...@@ -2203,10 +2204,16 @@ dict_foreign_add_to_cache( ...@@ -2203,10 +2204,16 @@ dict_foreign_add_to_cache(
} }
if (for_in_cache->referenced_table == NULL && ref_table) { if (for_in_cache->referenced_table == NULL && ref_table) {
dict_index_t* types_idx;
if (check_types) {
types_idx = for_in_cache->foreign_index;
} else {
types_idx = NULL;
}
index = dict_foreign_find_index(ref_table, index = dict_foreign_find_index(ref_table,
(const char**) for_in_cache->referenced_col_names, (const char**) for_in_cache->referenced_col_names,
for_in_cache->n_fields, for_in_cache->n_fields,
for_in_cache->foreign_index); types_idx);
if (index == NULL) { if (index == NULL) {
dict_foreign_error_report(ef, for_in_cache, dict_foreign_error_report(ef, for_in_cache,
...@@ -2230,10 +2237,16 @@ dict_foreign_add_to_cache( ...@@ -2230,10 +2237,16 @@ dict_foreign_add_to_cache(
} }
if (for_in_cache->foreign_table == NULL && for_table) { if (for_in_cache->foreign_table == NULL && for_table) {
dict_index_t* types_idx;
if (check_types) {
types_idx = for_in_cache->referenced_index;
} else {
types_idx = NULL;
}
index = dict_foreign_find_index(for_table, index = dict_foreign_find_index(for_table,
(const char**) for_in_cache->foreign_col_names, (const char**) for_in_cache->foreign_col_names,
for_in_cache->n_fields, for_in_cache->n_fields,
for_in_cache->referenced_index); types_idx);
if (index == NULL) { if (index == NULL) {
dict_foreign_error_report(ef, for_in_cache, dict_foreign_error_report(ef, for_in_cache,
......
...@@ -873,7 +873,7 @@ dict_load_table( ...@@ -873,7 +873,7 @@ dict_load_table(
dict_load_indexes(table, heap); dict_load_indexes(table, heap);
err = dict_load_foreigns(table->name); err = dict_load_foreigns(table->name, TRUE);
/* /*
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
...@@ -1092,8 +1092,9 @@ ulint ...@@ -1092,8 +1092,9 @@ ulint
dict_load_foreign( dict_load_foreign(
/*==============*/ /*==============*/
/* out: DB_SUCCESS or error code */ /* out: DB_SUCCESS or error code */
const char* id) /* in: foreign constraint id as a const char* id, /* in: foreign constraint id as a
null-terminated string */ null-terminated string */
ibool check_types)/* in: TRUE=check type compatibility */
{ {
dict_foreign_t* foreign; dict_foreign_t* foreign;
dict_table_t* sys_foreign; dict_table_t* sys_foreign;
...@@ -1105,7 +1106,6 @@ dict_load_foreign( ...@@ -1105,7 +1106,6 @@ dict_load_foreign(
rec_t* rec; rec_t* rec;
byte* field; byte* field;
ulint len; ulint len;
ulint err;
mtr_t mtr; mtr_t mtr;
#ifdef UNIV_SYNC_DEBUG #ifdef UNIV_SYNC_DEBUG
...@@ -1205,9 +1205,7 @@ dict_load_foreign( ...@@ -1205,9 +1205,7 @@ dict_load_foreign(
a new foreign key constraint but loading one from the data a new foreign key constraint but loading one from the data
dictionary. */ dictionary. */
err = dict_foreign_add_to_cache(foreign); return(dict_foreign_add_to_cache(foreign, check_types));
return(err);
} }
/*************************************************************************** /***************************************************************************
...@@ -1221,7 +1219,8 @@ ulint ...@@ -1221,7 +1219,8 @@ ulint
dict_load_foreigns( dict_load_foreigns(
/*===============*/ /*===============*/
/* out: DB_SUCCESS or error code */ /* out: DB_SUCCESS or error code */
const char* table_name) /* in: table name */ const char* table_name, /* in: table name */
ibool check_types) /* in: TRUE=check type compatibility */
{ {
btr_pcur_t pcur; btr_pcur_t pcur;
mem_heap_t* heap; mem_heap_t* heap;
...@@ -1320,7 +1319,7 @@ loop: ...@@ -1320,7 +1319,7 @@ loop:
/* Load the foreign constraint definition to the dictionary cache */ /* Load the foreign constraint definition to the dictionary cache */
err = dict_load_foreign(id); err = dict_load_foreign(id, check_types);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
btr_pcur_close(&pcur); btr_pcur_close(&pcur);
......
...@@ -189,7 +189,8 @@ ulint ...@@ -189,7 +189,8 @@ ulint
dict_foreign_add_to_cache( dict_foreign_add_to_cache(
/*======================*/ /*======================*/
/* out: DB_SUCCESS or error code */ /* out: DB_SUCCESS or error code */
dict_foreign_t* foreign); /* in, own: foreign key constraint */ dict_foreign_t* foreign, /* in, own: foreign key constraint */
ibool check_types); /* in: TRUE=check type compatibility */
/************************************************************************* /*************************************************************************
Checks if a table is referenced by foreign keys. */ Checks if a table is referenced by foreign keys. */
......
...@@ -81,7 +81,8 @@ ulint ...@@ -81,7 +81,8 @@ ulint
dict_load_foreigns( dict_load_foreigns(
/*===============*/ /*===============*/
/* out: DB_SUCCESS or error code */ /* out: DB_SUCCESS or error code */
const char* table_name); /* in: table name */ const char* table_name, /* in: table name */
ibool check_types); /* in: TRUE=check type compatibility */
/************************************************************************ /************************************************************************
Prints to the standard output information on all tables found in the data Prints to the standard output information on all tables found in the data
dictionary system table. */ dictionary system table. */
......
...@@ -1796,7 +1796,7 @@ row_table_add_foreign_constraints( ...@@ -1796,7 +1796,7 @@ row_table_add_foreign_constraints(
if (err == DB_SUCCESS) { if (err == DB_SUCCESS) {
/* Check that also referencing constraints are ok */ /* Check that also referencing constraints are ok */
err = dict_load_foreigns(name); err = dict_load_foreigns(name, trx->check_foreigns);
} }
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
...@@ -3204,6 +3204,8 @@ row_rename_table_for_mysql( ...@@ -3204,6 +3204,8 @@ row_rename_table_for_mysql(
goto funct_exit; goto funct_exit;
} }
err = dict_load_foreigns(new_name, trx->check_foreigns);
if (row_is_mysql_tmp_table_name(old_name)) { if (row_is_mysql_tmp_table_name(old_name)) {
/* MySQL is doing an ALTER TABLE command and it /* MySQL is doing an ALTER TABLE command and it
...@@ -3213,8 +3215,6 @@ row_rename_table_for_mysql( ...@@ -3213,8 +3215,6 @@ row_rename_table_for_mysql(
table. But we want to load also the foreign key table. But we want to load also the foreign key
constraint definitions for the original table name. */ constraint definitions for the original table name. */
err = dict_load_foreigns(new_name);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
fputs(" InnoDB: Error: in ALTER TABLE ", fputs(" InnoDB: Error: in ALTER TABLE ",
...@@ -3233,8 +3233,6 @@ row_rename_table_for_mysql( ...@@ -3233,8 +3233,6 @@ row_rename_table_for_mysql(
trx->error_state = DB_SUCCESS; trx->error_state = DB_SUCCESS;
} }
} else { } else {
err = dict_load_foreigns(new_name);
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
ut_print_timestamp(stderr); ut_print_timestamp(stderr);
......
...@@ -4183,6 +4183,10 @@ ha_innobase::rename_table( ...@@ -4183,6 +4183,10 @@ ha_innobase::rename_table(
trx->mysql_thd = current_thd; trx->mysql_thd = current_thd;
trx->mysql_query_str = &((*current_thd).query); trx->mysql_query_str = &((*current_thd).query);
if (current_thd->options & OPTION_NO_FOREIGN_KEY_CHECKS) {
trx->check_foreigns = FALSE;
}
name_len1 = strlen(from); name_len1 = strlen(from);
name_len2 = strlen(to); name_len2 = strlen(to);
......
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