summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2016-04-22 10:25:16 +0530
committerNisha Gopalakrishnan <nisha.gopalakrishnan@oracle.com>2016-04-22 10:25:16 +0530
commit3b6f9aac02b126db57fa3e3f1873713438d0a950 (patch)
tree44d9a28b92fea264e80ce422f6504261851037e0 /sql
parentfbf44eed3c69dc15047ac2d40c09dd0d16993fb0 (diff)
downloadmariadb-git-3b6f9aac02b126db57fa3e3f1873713438d0a950.tar.gz
BUG#23135731: INSERT WITH DUPLICATE KEY UPDATE REPORTS
INCORRECT ERROR. Analysis ======== INSERT with DUPLICATE KEY UPDATE and REPLACE on a table where foreign key constraint is defined fails with an incorrect 'duplicate entry' error rather than foreign key constraint violation error. As part of the bug fix for BUG#22037930, a new flag 'HA_CHECK_FK_ERROR' was added while checking for non fatal errors to manage FK errors based on the 'IGNORE' flag. For INSERT with DUPLICATE KEY UPDATE and REPLACE queries, the foreign key constraint violation error was marked as non-fatal, even though IGNORE was not set. Hence it continued with the duplicate key processing resulting in an incorrect error. Fix: === Foreign key violation errors are treated as non fatal only when the IGNORE is not set in the above mentioned queries. Hence reports the appropriate foreign key violation error.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_insert.cc23
1 files changed, 16 insertions, 7 deletions
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index a267108c847..dc7cb698476 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1521,16 +1521,25 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
insert_id_for_cur_row= table->file->insert_id_for_cur_row;
else
table->file->insert_id_for_cur_row= insert_id_for_cur_row;
- bool is_duplicate_key_error;
- if (table->file->is_fatal_error(error, HA_CHECK_DUP | HA_CHECK_FK_ERROR))
+
+ /*
+ If it is a FK constraint violation and 'ignore' flag is set,
+ report a warning instead of error.
+ */
+ if (info->ignore && !table->file->is_fatal_error(error,
+ HA_CHECK_FK_ERROR))
+ goto ok_or_after_trg_err;
+
+ if (table->file->is_fatal_error(error, HA_CHECK_DUP))
goto err;
- is_duplicate_key_error= table->file->is_fatal_error(error, 0);
- if (!is_duplicate_key_error)
+
+ if (!table->file->is_fatal_error(error, 0))
{
/*
- We come here when we had an ignorable error which is not a duplicate
- key error. In this we ignore error if ignore flag is set, otherwise
- report error as usual. We will not do any duplicate key processing.
+ We come here when we have an ignorable error which is not a duplicate
+ key error or FK error(Ex: Partition related errors). In this case we
+ ignore the error if ignore flag is set, otherwise report error as usual.
+ We will not do any duplicate key processing.
*/
if (info->ignore)
goto ok_or_after_trg_err; /* Ignoring a not fatal error, return 0 */