From d90d673daf4e1ed86e0701a35509f14d750ab9ca Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jun 2006 20:56:50 -0400 Subject: [PATCH 1/5] BUG#17138: Error in stored procedure due to fatal error when not really a fatal error. New handling of ignore error in place. mysql-test/t/partition.test: New test case sql/ha_ndbcluster.h: New handler method to check if error can be ignored sql/ha_partition.h: New handler method to check if error can be ignored sql/handler.h: New handler method to check if error can be ignored sql/sql_acl.cc: Use new handler method sql/sql_insert.cc: Use new handler method sql/sql_table.cc: Use new handler method sql/sql_union.cc: Use new handler method sql/sql_update.cc: Use new handler method --- mysql-test/t/partition.test | 23 +++++++++++++++++++++++ sql/ha_ndbcluster.h | 8 ++++++++ sql/ha_partition.h | 8 ++++++++ sql/handler.h | 25 +++++++++++++++++++++++-- sql/sql_acl.cc | 9 ++++----- sql/sql_insert.cc | 8 ++++++-- sql/sql_table.cc | 6 ++---- sql/sql_union.cc | 2 +- sql/sql_update.cc | 20 +++++++++++--------- 9 files changed, 86 insertions(+), 23 deletions(-) diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 05adb6866db..3037c409165 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -1135,4 +1135,27 @@ alter table t1 drop partition p2; use test; drop database db99; +# +#BUG 17138 Problem with stored procedure and analyze partition +# +create table t1 (a int) +partition by list (a) +(partition p0 values in (0)); + +insert into t1 values (0); +delimiter //; + +create procedure po () +begin + begin + declare continue handler for sqlexception begin end; + update ignore t1 set a = 1 where a = 0; + end; + prepare stmt1 from 'alter table t1'; + execute stmt1; +end// + +call po()// +delimiter ;// +drop table t1; --echo End of 5.1 tests diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index 9bcc549cb60..a994931843b 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -654,6 +654,14 @@ class ha_ndbcluster: public handler int get_default_no_partitions(ulonglong max_rows); bool get_no_parts(const char *name, uint *no_parts); void set_auto_partitions(partition_info *part_info); + virtual bool cannot_ignore_error(int error, uint flags) + { + if (!handler::cannot_ignore_error(error, flags)) + return FALSE; + if (error == HA_ERR_NO_PARTITION_FOUND) + return FALSE; + return TRUE; + } THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, diff --git a/sql/ha_partition.h b/sql/ha_partition.h index b52c8d92164..2bf9811827f 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -302,6 +302,14 @@ public: virtual void start_bulk_insert(ha_rows rows); virtual int end_bulk_insert(); + virtual bool cannot_ignore_error(int error, uint flags) + { + if (!handler::cannot_ignore_error(error, flags)) + return FALSE; + if (error == HA_ERR_NO_PARTITION_FOUND) + return FALSE; + return TRUE; + } /* ------------------------------------------------------------------------- MODULE full table scan diff --git a/sql/handler.h b/sql/handler.h index f459d52fdeb..771eeea948f 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -974,7 +974,28 @@ public: bool has_transactions() { return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0; } virtual uint extra_rec_buf_length() const { return 0; } - + + /* + This method is used to analyse the error to see whether the error + is ignorable or not, certain handlers can have more error that are + ignorable than others. E.g. the partition handler can get inserts + into a range where there is no partition and this is an ignorable + error. + */ +#define HA_CHECK_DUPP_KEY 1 +#define HA_CHECK_DUPP_UNIQUE 2 +#define HA_CHECK_DUPP (CHECK_DUPP_KEY + CHECK_DUPP_UNIQUE) + virtual bool cannot_ignore_error(int error, uint flags) + { + if (!error || + ((flags & HA_CHECK_DUPP_KEY) && + error == HA_ERR_FOUND_DUPP_KEY) || + ((flags & HA_CHECK_DUPP_UNIQUE) && + error == HA_ERR_FOUND_DUPP_UNIQUE)) + return FALSE; + return TRUE; + } + /* Number of rows in table. It will only be called if (table_flags() & (HA_HAS_RECORDS | HA_STATS_RECORDS_IS_EXACT)) != 0 @@ -1026,7 +1047,7 @@ public: DBUG_RETURN(rnd_end()); } int ha_reset(); - + /* this is necessary in many places, e.g. in HANDLER command */ int ha_index_or_rnd_end() { diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 4c2dfac6b8b..a656115711e 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2049,8 +2049,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, } else if ((error=table->file->ha_write_row(table->record[0]))) // insert { // This should never happen - if (error && error != HA_ERR_FOUND_DUPP_KEY && - error != HA_ERR_FOUND_DUPP_UNIQUE) /* purecov: inspected */ + if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP)) { table->file->print_error(error,MYF(0)); /* purecov: deadcode */ error= -1; /* purecov: deadcode */ @@ -2172,7 +2171,7 @@ static int replace_db_table(TABLE *table, const char *db, } else if (rights && (error= table->file->ha_write_row(table->record[0]))) { - if (error && error != HA_ERR_FOUND_DUPP_KEY) /* purecov: inspected */ + if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) goto table_error; /* purecov: deadcode */ } @@ -2744,7 +2743,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, else { error=table->file->ha_write_row(table->record[0]); - if (error && error != HA_ERR_FOUND_DUPP_KEY) + if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) goto table_error; /* purecov: deadcode */ } @@ -2862,7 +2861,7 @@ static int replace_routine_table(THD *thd, GRANT_NAME *grant_name, else { error=table->file->ha_write_row(table->record[0]); - if (error && error != HA_ERR_FOUND_DUPP_KEY) + if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) goto table_error; } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 0dae2b8f37b..9370c47c22e 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -979,6 +979,9 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) if (error != HA_WRITE_SKIP) goto err; table->file->restore_auto_increment(); // it's too early here! BUG#20188 + if (info->ignore && + !table->file->cannot_ignore_error(error, 0)) + goto ok_or_after_trg_err; if ((int) (key_nr = table->file->get_dup_key(error)) < 0) { error=HA_WRITE_SKIP; /* Database can't find key */ @@ -1062,7 +1065,8 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) if ((error=table->file->ha_update_row(table->record[1], table->record[0]))) { - if ((error == HA_ERR_FOUND_DUPP_KEY) && info->ignore) + if (info->ignore && + !table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) goto ok_or_after_trg_err; goto err; } @@ -1148,7 +1152,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) else if ((error=table->file->ha_write_row(table->record[0]))) { if (!info->ignore || - (error != HA_ERR_FOUND_DUPP_KEY && error != HA_ERR_FOUND_DUPP_UNIQUE)) + table->file->cannot_ignore_error(error, HA_CHECK_DUPP)) goto err; table->file->restore_auto_increment(); } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index a49b7a2cc42..25c5918dbe7 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6235,10 +6235,8 @@ copy_data_between_tables(TABLE *from,TABLE *to, } if ((error=to->file->ha_write_row((byte*) to->record[0]))) { - if ((!ignore && - handle_duplicates != DUP_REPLACE) || - (error != HA_ERR_FOUND_DUPP_KEY && - error != HA_ERR_FOUND_DUPP_UNIQUE)) + if (!ignore || + to->file->cannot_ignore_error(error, HA_CHECK_DUPP)) { if (error == HA_ERR_FOUND_DUPP_KEY) { diff --git a/sql/sql_union.cc b/sql/sql_union.cc index bf93f0d3bea..5ad5ecc6556 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -65,7 +65,7 @@ bool select_union::send_data(List &values) if ((error= table->file->ha_write_row(table->record[0]))) { /* create_myisam_from_heap will generate error if needed */ - if (error != HA_ERR_FOUND_DUPP_KEY && error != HA_ERR_FOUND_DUPP_UNIQUE && + if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP) && create_myisam_from_heap(thd, table, &tmp_table_param, error, 1)) return 1; } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index e917c1358ef..c84492b9726 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -541,13 +541,14 @@ int mysql_update(THD *thd, break; } } - else if (!ignore || error != HA_ERR_FOUND_DUPP_KEY) + else if (!ignore || + table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) { /* - If (ignore && error == HA_ERR_FOUND_DUPP_KEY) we don't have to + If (ignore && error is ignorable) we don't have to do anything; otherwise... */ - if (error != HA_ERR_FOUND_DUPP_KEY) + if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) thd->fatal_error(); /* Other handler errors are fatal */ table->file->print_error(error,MYF(0)); error= 1; @@ -1417,13 +1418,14 @@ bool multi_update::send_data(List ¬_used_values) table->record[0]))) { updated--; - if (!ignore || error != HA_ERR_FOUND_DUPP_KEY) + if (!ignore || + table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) { /* - If (ignore && error == HA_ERR_FOUND_DUPP_KEY) we don't have to + If (ignore && error == is ignorable) we don't have to do anything; otherwise... */ - if (error != HA_ERR_FOUND_DUPP_KEY) + if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) thd->fatal_error(); /* Other handler errors are fatal */ table->file->print_error(error,MYF(0)); DBUG_RETURN(1); @@ -1452,8 +1454,7 @@ bool multi_update::send_data(List ¬_used_values) /* Write row, ignoring duplicated updates to a row */ if ((error= tmp_table->file->ha_write_row(tmp_table->record[0]))) { - if (error != HA_ERR_FOUND_DUPP_KEY && - error != HA_ERR_FOUND_DUPP_UNIQUE && + if (tmp_table->file->cannot_ignore_error(error, HA_CHECK_DUPP) && create_myisam_from_heap(thd, tmp_table, tmp_table_param + offset, error, 1)) { @@ -1576,7 +1577,8 @@ int multi_update::do_updates(bool from_send_error) if ((local_error=table->file->ha_update_row(table->record[1], table->record[0]))) { - if (!ignore || local_error != HA_ERR_FOUND_DUPP_KEY) + if (!ignore || + table->file->cannot_ignore_error(local_error, HA_CHECK_DUPP_KEY)) goto err; } updated++; From 7ac2e509cc8dedfd2dbdc8684e7b502bea5e7038 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jun 2006 22:49:00 -0400 Subject: [PATCH 2/5] Fixes --- sql/handler.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/handler.h b/sql/handler.h index 771eeea948f..ef2f08a036c 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -984,7 +984,7 @@ public: */ #define HA_CHECK_DUPP_KEY 1 #define HA_CHECK_DUPP_UNIQUE 2 -#define HA_CHECK_DUPP (CHECK_DUPP_KEY + CHECK_DUPP_UNIQUE) +#define HA_CHECK_DUPP (HA_CHECK_DUPP_KEY + HA_CHECK_DUPP_UNIQUE) virtual bool cannot_ignore_error(int error, uint flags) { if (!error || From 7dd728c8ce00d80b736aa52bab84e2ad826ea3f6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Jun 2006 23:13:42 -0400 Subject: [PATCH 3/5] New test case --- mysql-test/r/partition.result | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index fa1baaec07e..b51436e6747 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1043,4 +1043,19 @@ alter table t1 add partition (partition p2 values in (3)); alter table t1 drop partition p2; use test; drop database db99; +create table t1 (a int) +partition by list (a) +(partition p0 values in (0)); +insert into t1 values (0); +create procedure po () +begin +begin +declare continue handler for sqlexception begin end; +update ignore t1 set a = 1 where a = 0; +end; +prepare stmt1 from 'alter table t1'; +execute stmt1; +end// +call po()// +drop table t1; End of 5.1 tests From 897810e961d9b9a3916332fee878369f703c38c7 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Jun 2006 16:52:40 -0400 Subject: [PATCH 4/5] BUG#17138: Crash in stored procedure after fatal error that wasn't a real fatal error sql/handler.h: Handle HA_ERR_FOUND_DUPP_KEY and HA_ERR_FOUND_DUPP_UNIQUE similarly sql/item_sum.cc: fix sql/sql_select.cc: fix --- sql/handler.h | 8 +++++--- sql/item_sum.cc | 3 +-- sql/sql_select.cc | 9 ++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sql/handler.h b/sql/handler.h index b53c0a9c101..048657e419b 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -977,6 +977,9 @@ public: ignorable than others. E.g. the partition handler can get inserts into a range where there is no partition and this is an ignorable error. + HA_ERR_FOUND_DUPP_UNIQUE is a special case in MyISAM that means the + same thing as HA_ERR_FOUND_DUPP_KEY but can in some cases lead to + a slightly different error message. */ #define HA_CHECK_DUPP_KEY 1 #define HA_CHECK_DUPP_UNIQUE 2 @@ -985,9 +988,8 @@ public: { if (!error || ((flags & HA_CHECK_DUPP_KEY) && - error == HA_ERR_FOUND_DUPP_KEY) || - ((flags & HA_CHECK_DUPP_UNIQUE) && - error == HA_ERR_FOUND_DUPP_UNIQUE)) + (error == HA_ERR_FOUND_DUPP_KEY || + error == HA_ERR_FOUND_DUPP_UNIQUE))) return FALSE; return TRUE; } diff --git a/sql/item_sum.cc b/sql/item_sum.cc index d6bc2c326d6..ff37ceaa6fe 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -2663,8 +2663,7 @@ bool Item_sum_count_distinct::add() return tree->unique_add(table->record[0] + table->s->null_bytes); } if ((error= table->file->ha_write_row(table->record[0])) && - error != HA_ERR_FOUND_DUPP_KEY && - error != HA_ERR_FOUND_DUPP_UNIQUE) + table->file->cannot_ignore_error(error, HA_CHECK_DUPP)) return TRUE; return FALSE; } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e9e2a4ed1e0..add4746c819 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9354,9 +9354,9 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, /* copy row that filled HEAP table */ if ((write_err=new_table.file->write_row(table->record[0]))) { - if (write_err != HA_ERR_FOUND_DUPP_KEY && - write_err != HA_ERR_FOUND_DUPP_UNIQUE || !ignore_last_dupp_key_error) - goto err; + if (new_table.file->cannot_ignore_error(write_err, HA_CHECK_DUPP) || + !ignore_last_dupp_key_error) + goto err; } /* remove heap table and change to use myisam table */ @@ -10777,8 +10777,7 @@ end_write(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), join->found_records++; if ((error=table->file->write_row(table->record[0]))) { - if (error == HA_ERR_FOUND_DUPP_KEY || - error == HA_ERR_FOUND_DUPP_UNIQUE) + if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP)) goto end; if (create_myisam_from_heap(join->thd, table, &join->tmp_table_param, error,1)) From 532915484940221bc3c9a3090667c0b441183517 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 21 Jun 2006 20:55:33 -0400 Subject: [PATCH 5/5] BUG#17138: Error in stored procedure Review comments mysql-test/t/partition.test: Changed procedure names ensured procedures were dropped sql/ha_ndbcluster.h: Improved name of method sql/ha_partition.h: Improved name of method sql/handler.h: Improved name of method Removed deprecated constants sql/item_sum.cc: Improved name of method sql/sql_acl.cc: Improved name of method sql/sql_insert.cc: Removed use of HA_WRITE_SKIP and introduced is_fatal_error instead sql/sql_select.cc: Improved name of method sql/sql_table.cc: Improved name of method Reintroduced dead code for future possible use sql/sql_union.cc: Improved name of method sql/sql_update.cc: Improved name of method --- mysql-test/t/partition.test | 8 ++++++-- sql/ha_ndbcluster.h | 4 ++-- sql/ha_partition.h | 4 ++-- sql/handler.h | 7 +------ sql/item_sum.cc | 2 +- sql/sql_acl.cc | 8 ++++---- sql/sql_insert.cc | 13 +++++++------ sql/sql_select.cc | 4 ++-- sql/sql_table.cc | 5 +++-- sql/sql_union.cc | 2 +- sql/sql_update.cc | 12 ++++++------ 11 files changed, 35 insertions(+), 34 deletions(-) diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index d5ce7c5b797..8cfcc059920 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -1202,6 +1202,8 @@ drop database db99; # #BUG 17138 Problem with stored procedure and analyze partition # +drop procedure mysqltest_1 if exists; + create table t1 (a int) partition by list (a) (partition p0 values in (0)); @@ -1209,7 +1211,7 @@ partition by list (a) insert into t1 values (0); delimiter //; -create procedure po () +create procedure mysqltest_1 () begin begin declare continue handler for sqlexception begin end; @@ -1219,7 +1221,9 @@ begin execute stmt1; end// -call po()// +call mysqltest_1()// delimiter ;// drop table t1; +drop procedure mysqltest_1; + --echo End of 5.1 tests diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index a994931843b..4261e9604b5 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -654,9 +654,9 @@ class ha_ndbcluster: public handler int get_default_no_partitions(ulonglong max_rows); bool get_no_parts(const char *name, uint *no_parts); void set_auto_partitions(partition_info *part_info); - virtual bool cannot_ignore_error(int error, uint flags) + virtual bool is_fatal_error(int error, uint flags) { - if (!handler::cannot_ignore_error(error, flags)) + if (!handler::is_fatal_error(error, flags)) return FALSE; if (error == HA_ERR_NO_PARTITION_FOUND) return FALSE; diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 2bf9811827f..4b85ddd2def 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -302,9 +302,9 @@ public: virtual void start_bulk_insert(ha_rows rows); virtual int end_bulk_insert(); - virtual bool cannot_ignore_error(int error, uint flags) + virtual bool is_fatal_error(int error, uint flags) { - if (!handler::cannot_ignore_error(error, flags)) + if (!handler::is_fatal_error(error, flags)) return FALSE; if (error == HA_ERR_NO_PARTITION_FOUND) return FALSE; diff --git a/sql/handler.h b/sql/handler.h index 048657e419b..3e42938b5a3 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -216,11 +216,6 @@ #define HA_BLOCK_LOCK 256 /* unlock when reading some records */ #define HA_OPEN_TEMPORARY 512 - /* Errors on write which is recoverable (Key exist) */ -#define HA_WRITE_SKIP 121 /* Duplicate key on write */ -#define HA_READ_CHECK 123 /* Update with is recoverable */ -#define HA_CANT_DO_THAT 131 /* Databasehandler can't do it */ - /* Some key definitions */ #define HA_KEY_NULL_LENGTH 1 #define HA_KEY_BLOB_LENGTH 2 @@ -984,7 +979,7 @@ public: #define HA_CHECK_DUPP_KEY 1 #define HA_CHECK_DUPP_UNIQUE 2 #define HA_CHECK_DUPP (HA_CHECK_DUPP_KEY + HA_CHECK_DUPP_UNIQUE) - virtual bool cannot_ignore_error(int error, uint flags) + virtual bool is_fatal_error(int error, uint flags) { if (!error || ((flags & HA_CHECK_DUPP_KEY) && diff --git a/sql/item_sum.cc b/sql/item_sum.cc index ff37ceaa6fe..caaa111645a 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -2663,7 +2663,7 @@ bool Item_sum_count_distinct::add() return tree->unique_add(table->record[0] + table->s->null_bytes); } if ((error= table->file->ha_write_row(table->record[0])) && - table->file->cannot_ignore_error(error, HA_CHECK_DUPP)) + table->file->is_fatal_error(error, HA_CHECK_DUPP)) return TRUE; return FALSE; } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index e231c00c678..18591052a1f 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -2049,7 +2049,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, } else if ((error=table->file->ha_write_row(table->record[0]))) // insert { // This should never happen - if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP)) + if (table->file->is_fatal_error(error, HA_CHECK_DUPP)) { table->file->print_error(error,MYF(0)); /* purecov: deadcode */ error= -1; /* purecov: deadcode */ @@ -2171,7 +2171,7 @@ static int replace_db_table(TABLE *table, const char *db, } else if (rights && (error= table->file->ha_write_row(table->record[0]))) { - if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) + if (table->file->is_fatal_error(error, HA_CHECK_DUPP_KEY)) goto table_error; /* purecov: deadcode */ } @@ -2743,7 +2743,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, else { error=table->file->ha_write_row(table->record[0]); - if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) + if (table->file->is_fatal_error(error, HA_CHECK_DUPP_KEY)) goto table_error; /* purecov: deadcode */ } @@ -2861,7 +2861,7 @@ static int replace_routine_table(THD *thd, GRANT_NAME *grant_name, else { error=table->file->ha_write_row(table->record[0]); - if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) + if (table->file->is_fatal_error(error, HA_CHECK_DUPP_KEY)) goto table_error; } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 0e43eba4dcc..bb6378eece9 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -976,15 +976,16 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) while ((error=table->file->ha_write_row(table->record[0]))) { uint key_nr; - if (error != HA_WRITE_SKIP) + bool is_duplicate_key_error; + if (table->file->is_fatal_error(error, HA_CHECK_DUPP)) goto err; table->file->restore_auto_increment(); // it's too early here! BUG#20188 - if (info->ignore && - !table->file->cannot_ignore_error(error, 0)) + is_duplicate_key_error= table->file->is_fatal_error(error, 0); + if (info->ignore && !is_duplicate_key_error) goto ok_or_after_trg_err; if ((int) (key_nr = table->file->get_dup_key(error)) < 0) { - error=HA_WRITE_SKIP; /* Database can't find key */ + error=HA_ERR_FOUND_DUPP_KEY; /* Database can't find key */ goto err; } /* Read all columns for the row we are going to replace */ @@ -1066,7 +1067,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) table->record[0]))) { if (info->ignore && - !table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) + !table->file->is_fatal_error(error, HA_CHECK_DUPP_KEY)) goto ok_or_after_trg_err; goto err; } @@ -1152,7 +1153,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) else if ((error=table->file->ha_write_row(table->record[0]))) { if (!info->ignore || - table->file->cannot_ignore_error(error, HA_CHECK_DUPP)) + table->file->is_fatal_error(error, HA_CHECK_DUPP)) goto err; table->file->restore_auto_increment(); } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index add4746c819..89ca6c7dc6c 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9354,7 +9354,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, /* copy row that filled HEAP table */ if ((write_err=new_table.file->write_row(table->record[0]))) { - if (new_table.file->cannot_ignore_error(write_err, HA_CHECK_DUPP) || + if (new_table.file->is_fatal_error(write_err, HA_CHECK_DUPP) || !ignore_last_dupp_key_error) goto err; } @@ -10777,7 +10777,7 @@ end_write(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), join->found_records++; if ((error=table->file->write_row(table->record[0]))) { - if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP)) + if (table->file->is_fatal_error(error, HA_CHECK_DUPP)) goto end; if (create_myisam_from_heap(join->thd, table, &join->tmp_table_param, error,1)) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index e6ccaa2d9f2..3bf4c0bd99b 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6269,9 +6269,10 @@ copy_data_between_tables(TABLE *from,TABLE *to, if ((error=to->file->ha_write_row((byte*) to->record[0]))) { if (!ignore || - to->file->cannot_ignore_error(error, HA_CHECK_DUPP)) + handle_duplicates != DUP_REPLACE || /* Currently always false */ + to->file->is_fatal_error(error, HA_CHECK_DUPP)) { - if (error == HA_ERR_FOUND_DUPP_KEY) + if (!to->file->is_fatal_error(error, HA_CHECK_DUPP)) { uint key_nr= to->file->get_dup_key(error); if ((int) key_nr >= 0) diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 5ad5ecc6556..fd4529090d4 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -65,7 +65,7 @@ bool select_union::send_data(List &values) if ((error= table->file->ha_write_row(table->record[0]))) { /* create_myisam_from_heap will generate error if needed */ - if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP) && + if (table->file->is_fatal_error(error, HA_CHECK_DUPP) && create_myisam_from_heap(thd, table, &tmp_table_param, error, 1)) return 1; } diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 0fb221b25a7..414c2b353b3 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -542,13 +542,13 @@ int mysql_update(THD *thd, } } else if (!ignore || - table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) + table->file->is_fatal_error(error, HA_CHECK_DUPP_KEY)) { /* If (ignore && error is ignorable) we don't have to do anything; otherwise... */ - if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) + if (table->file->is_fatal_error(error, HA_CHECK_DUPP_KEY)) thd->fatal_error(); /* Other handler errors are fatal */ table->file->print_error(error,MYF(0)); error= 1; @@ -1424,13 +1424,13 @@ bool multi_update::send_data(List ¬_used_values) { updated--; if (!ignore || - table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) + table->file->is_fatal_error(error, HA_CHECK_DUPP_KEY)) { /* If (ignore && error == is ignorable) we don't have to do anything; otherwise... */ - if (table->file->cannot_ignore_error(error, HA_CHECK_DUPP_KEY)) + if (table->file->is_fatal_error(error, HA_CHECK_DUPP_KEY)) thd->fatal_error(); /* Other handler errors are fatal */ table->file->print_error(error,MYF(0)); DBUG_RETURN(1); @@ -1459,7 +1459,7 @@ bool multi_update::send_data(List ¬_used_values) /* Write row, ignoring duplicated updates to a row */ if ((error= tmp_table->file->ha_write_row(tmp_table->record[0]))) { - if (tmp_table->file->cannot_ignore_error(error, HA_CHECK_DUPP) && + if (tmp_table->file->is_fatal_error(error, HA_CHECK_DUPP) && create_myisam_from_heap(thd, tmp_table, tmp_table_param + offset, error, 1)) { @@ -1583,7 +1583,7 @@ int multi_update::do_updates(bool from_send_error) table->record[0]))) { if (!ignore || - table->file->cannot_ignore_error(local_error, HA_CHECK_DUPP_KEY)) + table->file->is_fatal_error(local_error, HA_CHECK_DUPP_KEY)) goto err; } updated++;