summaryrefslogtreecommitdiff
path: root/innobase
diff options
context:
space:
mode:
authorheikki@hundin.mysql.fi <>2004-02-09 23:57:29 +0200
committerheikki@hundin.mysql.fi <>2004-02-09 23:57:29 +0200
commitd9790a406c69a46eb197cea725c1e7c7e480ac41 (patch)
tree4b1a405fb8e787dcba8a5a3f77ac537aa6b874fe /innobase
parentd2d1e6f7261846c34a93fe17c1c10a3a0be2e3ca (diff)
downloadmariadb-git-d9790a406c69a46eb197cea725c1e7c7e480ac41.tar.gz
row0mysql.c:
Allow always DROPping of a table which is only referenced by FOREIGN KEY constraints from the same table Many files: Do not let REPLACE to perform internally an UPDATE if the table is referenced by a FOREIGN KEY: the manual says that REPLACE must resolve a duplicate key error semantically with DELETE(s) + INSERT, and not by an UPDATE; the internal update caused foreign key checks and cascaded operations to behave in a semantically wrong way
Diffstat (limited to 'innobase')
-rw-r--r--innobase/dict/dict0dict.c18
-rw-r--r--innobase/include/dict0dict.h9
-rw-r--r--innobase/row/row0mysql.c7
3 files changed, 34 insertions, 0 deletions
diff --git a/innobase/dict/dict0dict.c b/innobase/dict/dict0dict.c
index e0597c66dba..5b2a16ce9f3 100644
--- a/innobase/dict/dict0dict.c
+++ b/innobase/dict/dict0dict.c
@@ -1846,6 +1846,24 @@ dict_index_build_internal_non_clust(
/*====================== FOREIGN KEY PROCESSING ========================*/
/*************************************************************************
+Checks if a table is referenced by foreign keys. */
+
+ibool
+dict_table_referenced_by_foreign_key(
+/*=================================*/
+ /* out: TRUE if table is referenced by a
+ foreign key */
+ dict_table_t* table) /* in: InnoDB table */
+{
+ if (UT_LIST_GET_LEN(table->referenced_list) > 0) {
+
+ return(TRUE);
+ }
+
+ return(FALSE);
+}
+
+/*************************************************************************
Frees a foreign key struct. */
static
void
diff --git a/innobase/include/dict0dict.h b/innobase/include/dict0dict.h
index 6f56c54224b..7d55521f228 100644
--- a/innobase/include/dict0dict.h
+++ b/innobase/include/dict0dict.h
@@ -206,6 +206,15 @@ dict_foreign_add_to_cache(
/* out: DB_SUCCESS or error code */
dict_foreign_t* foreign); /* in, own: foreign key constraint */
/*************************************************************************
+Checks if a table is referenced by foreign keys. */
+
+ibool
+dict_table_referenced_by_foreign_key(
+/*=================================*/
+ /* out: TRUE if table is referenced by a
+ foreign key */
+ dict_table_t* table); /* in: InnoDB table */
+/*************************************************************************
Scans a table create SQL string and adds to the data dictionary
the foreign key constraints declared in the string. This function
should be called after the indexes for a table have been created.
diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c
index ce88bcc5933..a95d0fc6b95 100644
--- a/innobase/row/row0mysql.c
+++ b/innobase/row/row0mysql.c
@@ -1997,8 +1997,15 @@ row_drop_table_for_mysql(
goto funct_exit;
}
+ /* Check if the table is referenced by foreign key constraints from
+ some other table (not the table itself) */
+
foreign = UT_LIST_GET_FIRST(table->referenced_list);
+ while (foreign && foreign->foreign_table == table) {
+ foreign = UT_LIST_GET_NEXT(referenced_list, foreign);
+ }
+
if (foreign && trx->check_foreigns) {
char* buf = dict_foreign_err_buf;