From d9c541cb1be5b239787833d9d499067d44ea44d3 Mon Sep 17 00:00:00 2001 From: Nisha Gopalakrishnan Date: Wed, 10 Feb 2016 19:57:17 +0530 Subject: 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. --- sql/sql_update.cc | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'sql/sql_update.cc') diff --git a/sql/sql_update.cc b/sql/sql_update.cc index a29d474fbfc..64d1b3e49dc 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -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 ¬_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 ¬_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++; -- cgit v1.2.1 From 24ac546d0f16d5f56b11c068e4f187a9c4c56bd0 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 20 Apr 2016 18:27:23 +0200 Subject: use consistent error messaging for IGNORE 1. the same message text for INSERT and INSERT IGNORE 2. no new warnings in UPDATE IGNORE yet (big change for 5.5) and replace a commonly used expression with a named constant --- sql/sql_update.cc | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'sql/sql_update.cc') diff --git a/sql/sql_update.cc b/sql/sql_update.cc index d1b6e945b23..f134e0ba266 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -774,8 +774,7 @@ int mysql_update(THD *thd, error= 0; } else if (!ignore || - table->file->is_fatal_error(error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + table->file->is_fatal_error(error, HA_CHECK_ALL)) { /* If (ignore && error is ignorable) we don't have to @@ -783,8 +782,7 @@ int mysql_update(THD *thd, */ myf flags= 0; - if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + if (table->file->is_fatal_error(error, HA_CHECK_ALL)) flags|= ME_FATALERROR; /* Other handler errors are fatal */ prepare_record_for_error_message(error, table); @@ -792,9 +790,6 @@ 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 && @@ -1974,8 +1969,7 @@ int multi_update::send_data(List ¬_used_values) { updated--; if (!ignore || - table->file->is_fatal_error(error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + table->file->is_fatal_error(error, HA_CHECK_ALL)) { /* If (ignore && error == is ignorable) we don't have to @@ -1983,17 +1977,13 @@ int multi_update::send_data(List ¬_used_values) */ myf flags= 0; - if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY | - HA_CHECK_FK_ERROR)) + if (table->file->is_fatal_error(error, HA_CHECK_ALL)) 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 { @@ -2266,15 +2256,11 @@ 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 | - HA_CHECK_FK_ERROR)) + table->file->is_fatal_error(local_error, HA_CHECK_ALL)) { err_table= table; 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++; -- cgit v1.2.1 From 99cd5a962c53e35620cdeeca35dfab4ab4b3bb4c Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Mon, 23 May 2016 21:15:01 +0300 Subject: MDEV-8989: ORDER BY optimizer ignores equality propagation Variant #4 of the fix. Make ORDER BY optimization functions take into account multiple equalities. This is done in several places: - remove_const() checks whether we can sort the first table in the join, or we need to put rows into temp.table and then sort. - test_if_order_by_key() checks whether there are indexes that can be used to produce the required ordering - make_unireg_sortorder() constructs sort criteria for filesort. --- sql/sql_update.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_update.cc') diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 3c0827bb164..4221025da28 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -567,7 +567,7 @@ int mysql_update(THD *thd, Filesort_tracker *fs_tracker= thd->lex->explain->get_upd_del_plan()->filesort_tracker; - if (!(sortorder=make_unireg_sortorder(thd, order, &length, NULL)) || + if (!(sortorder=make_unireg_sortorder(thd, NULL, 0, order, &length, NULL)) || (table->sort.found_records= filesort(thd, table, sortorder, length, select, limit, true, -- cgit v1.2.1 From 911af69d1e13e5dff43b550da19d3d4a0ae07e96 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Mon, 20 Jun 2016 14:35:58 +0200 Subject: MDEV-5973: MySQL Bug#11757486:49539: NON-DESCRIPTIVE ERR (ERROR 0 FROM STORAGE ENGINE) WITH MULTI-TABLE UPDATE Condition in processing IGNORE clause for UPDATE & multi-table UPDATE made the same. --- sql/sql_update.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_update.cc') diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 2507c3fec53..b2af075e2f4 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1584,7 +1584,7 @@ bool mysql_multi_update(THD *thd, DBUG_RETURN(TRUE); } - thd->abort_on_warning= thd->is_strict_mode(); + thd->abort_on_warning= !ignore && thd->is_strict_mode(); List total_list; res= mysql_select(thd, &select_lex->ref_pointer_array, -- cgit v1.2.1