mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
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.
This commit is contained in:
@ -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 */
|
||||
|
Reference in New Issue
Block a user