From d9790a406c69a46eb197cea725c1e7c7e480ac41 Mon Sep 17 00:00:00 2001 From: "heikki@hundin.mysql.fi" <> Date: Mon, 9 Feb 2004 23:57:29 +0200 Subject: 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 --- sql/sql_insert.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 97b7c1db03d..4d7a9f7e508 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -442,7 +442,15 @@ int write_record(TABLE *table,COPY_INFO *info) HA_READ_KEY_EXACT)))) goto err; } - if (last_uniq_key(table,key_nr)) + /* + The manual defines the REPLACE semantics that it is either an INSERT or + DELETE(s) + INSERT; FOREIGN KEY checks do not function in the defined + way if we allow MySQL to convert the latter operation internally to an + UPDATE. + */ + + if (last_uniq_key(table,key_nr) + && !table->file->referenced_by_foreign_key()) { if ((error=table->file->update_row(table->record[1],table->record[0]))) goto err; -- cgit v1.2.1