1
0
mirror of https://github.com/MariaDB/server.git synced 2026-01-06 05:22:24 +03:00

BUG#22037930: INSERT IGNORE FAILS TO IGNORE FOREIGN KEY

CONSTRAINT.

Analysis
=======

INSERT and UPDATE operations using the IGNORE keyword which
causes FOREIGN KEY constraint violations reports an error
despite using the IGNORE keyword.

Foreign key violation errors were not ignored and reported
as errors instead of warnings even when IGNORE was set.

Fix
===
Added code to ignore the foreign key violation errors and
report them as warnings when the IGNORE keyword is used.
This commit is contained in:
Nisha Gopalakrishnan
2016-02-10 19:57:17 +05:30
parent 1fb6d4e6bf
commit d9c541cb1b
6 changed files with 141 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -735,7 +735,8 @@ int mysql_update(THD *thd,
error= 0;
}
else if (!ignore ||
table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
HA_CHECK_FK_ERROR))
{
/*
If (ignore && error is ignorable) we don't have to
@@ -743,7 +744,8 @@ int mysql_update(THD *thd,
*/
myf flags= 0;
if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
HA_CHECK_FK_ERROR))
flags|= ME_FATALERROR; /* Other handler errors are fatal */
prepare_record_for_error_message(error, table);
@@ -751,6 +753,9 @@ int mysql_update(THD *thd,
error= 1;
break;
}
else if (ignore && !table->file->is_fatal_error(error,
HA_CHECK_FK_ERROR))
warn_fk_constraint_violation(thd, table, error);
}
if (table->triggers &&
@@ -1883,7 +1888,8 @@ bool multi_update::send_data(List<Item> &not_used_values)
{
updated--;
if (!ignore ||
table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
HA_CHECK_FK_ERROR))
{
/*
If (ignore && error == is ignorable) we don't have to
@@ -1891,13 +1897,17 @@ bool multi_update::send_data(List<Item> &not_used_values)
*/
myf flags= 0;
if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY))
if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
HA_CHECK_FK_ERROR))
flags|= ME_FATALERROR; /* Other handler errors are fatal */
prepare_record_for_error_message(error, table);
table->file->print_error(error,MYF(flags));
DBUG_RETURN(1);
}
else if (ignore && !table->file->is_fatal_error(error,
HA_CHECK_FK_ERROR))
warn_fk_constraint_violation(thd, table, error);
}
else
{
@@ -2138,8 +2148,12 @@ int multi_update::do_updates()
local_error != HA_ERR_RECORD_IS_THE_SAME)
{
if (!ignore ||
table->file->is_fatal_error(local_error, HA_CHECK_DUP_KEY))
table->file->is_fatal_error(local_error, HA_CHECK_DUP_KEY |
HA_CHECK_FK_ERROR))
goto err;
else if (ignore && !table->file->is_fatal_error(local_error,
HA_CHECK_FK_ERROR))
warn_fk_constraint_violation(thd, table, local_error);
}
if (local_error != HA_ERR_RECORD_IS_THE_SAME)
updated++;