Commit a8e6967c authored by mikael@dator5.(none)'s avatar mikael@dator5.(none)

BUG#17138: Error in stored procedure

Review comments
parent cd93441a
...@@ -1202,6 +1202,8 @@ drop database db99; ...@@ -1202,6 +1202,8 @@ drop database db99;
# #
#BUG 17138 Problem with stored procedure and analyze partition #BUG 17138 Problem with stored procedure and analyze partition
# #
drop procedure mysqltest_1 if exists;
create table t1 (a int) create table t1 (a int)
partition by list (a) partition by list (a)
(partition p0 values in (0)); (partition p0 values in (0));
...@@ -1209,7 +1211,7 @@ partition by list (a) ...@@ -1209,7 +1211,7 @@ partition by list (a)
insert into t1 values (0); insert into t1 values (0);
delimiter //; delimiter //;
create procedure po () create procedure mysqltest_1 ()
begin begin
begin begin
declare continue handler for sqlexception begin end; declare continue handler for sqlexception begin end;
...@@ -1219,7 +1221,9 @@ begin ...@@ -1219,7 +1221,9 @@ begin
execute stmt1; execute stmt1;
end// end//
call po()// call mysqltest_1()//
delimiter ;// delimiter ;//
drop table t1; drop table t1;
drop procedure mysqltest_1;
--echo End of 5.1 tests --echo End of 5.1 tests
...@@ -654,9 +654,9 @@ class ha_ndbcluster: public handler ...@@ -654,9 +654,9 @@ class ha_ndbcluster: public handler
int get_default_no_partitions(ulonglong max_rows); int get_default_no_partitions(ulonglong max_rows);
bool get_no_parts(const char *name, uint *no_parts); bool get_no_parts(const char *name, uint *no_parts);
void set_auto_partitions(partition_info *part_info); 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; return FALSE;
if (error == HA_ERR_NO_PARTITION_FOUND) if (error == HA_ERR_NO_PARTITION_FOUND)
return FALSE; return FALSE;
......
...@@ -302,9 +302,9 @@ class ha_partition :public handler ...@@ -302,9 +302,9 @@ class ha_partition :public handler
virtual void start_bulk_insert(ha_rows rows); virtual void start_bulk_insert(ha_rows rows);
virtual int end_bulk_insert(); 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; return FALSE;
if (error == HA_ERR_NO_PARTITION_FOUND) if (error == HA_ERR_NO_PARTITION_FOUND)
return FALSE; return FALSE;
......
...@@ -216,11 +216,6 @@ ...@@ -216,11 +216,6 @@
#define HA_BLOCK_LOCK 256 /* unlock when reading some records */ #define HA_BLOCK_LOCK 256 /* unlock when reading some records */
#define HA_OPEN_TEMPORARY 512 #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 */ /* Some key definitions */
#define HA_KEY_NULL_LENGTH 1 #define HA_KEY_NULL_LENGTH 1
#define HA_KEY_BLOB_LENGTH 2 #define HA_KEY_BLOB_LENGTH 2
...@@ -984,7 +979,7 @@ class handler :public Sql_alloc ...@@ -984,7 +979,7 @@ class handler :public Sql_alloc
#define HA_CHECK_DUPP_KEY 1 #define HA_CHECK_DUPP_KEY 1
#define HA_CHECK_DUPP_UNIQUE 2 #define HA_CHECK_DUPP_UNIQUE 2
#define HA_CHECK_DUPP (HA_CHECK_DUPP_KEY + HA_CHECK_DUPP_UNIQUE) #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 || if (!error ||
((flags & HA_CHECK_DUPP_KEY) && ((flags & HA_CHECK_DUPP_KEY) &&
......
...@@ -2663,7 +2663,7 @@ bool Item_sum_count_distinct::add() ...@@ -2663,7 +2663,7 @@ bool Item_sum_count_distinct::add()
return tree->unique_add(table->record[0] + table->s->null_bytes); return tree->unique_add(table->record[0] + table->s->null_bytes);
} }
if ((error= table->file->ha_write_row(table->record[0])) && 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 TRUE;
return FALSE; return FALSE;
} }
......
...@@ -2049,7 +2049,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, ...@@ -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 else if ((error=table->file->ha_write_row(table->record[0]))) // insert
{ // This should never happen { // 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 */ table->file->print_error(error,MYF(0)); /* purecov: deadcode */
error= -1; /* purecov: deadcode */ error= -1; /* purecov: deadcode */
...@@ -2171,7 +2171,7 @@ static int replace_db_table(TABLE *table, const char *db, ...@@ -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]))) 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 */ goto table_error; /* purecov: deadcode */
} }
...@@ -2743,7 +2743,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, ...@@ -2743,7 +2743,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table,
else else
{ {
error=table->file->ha_write_row(table->record[0]); 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 */ goto table_error; /* purecov: deadcode */
} }
...@@ -2861,7 +2861,7 @@ static int replace_routine_table(THD *thd, GRANT_NAME *grant_name, ...@@ -2861,7 +2861,7 @@ static int replace_routine_table(THD *thd, GRANT_NAME *grant_name,
else else
{ {
error=table->file->ha_write_row(table->record[0]); 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; goto table_error;
} }
......
...@@ -976,15 +976,16 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) ...@@ -976,15 +976,16 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
while ((error=table->file->ha_write_row(table->record[0]))) while ((error=table->file->ha_write_row(table->record[0])))
{ {
uint key_nr; 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; goto err;
table->file->restore_auto_increment(); // it's too early here! BUG#20188 table->file->restore_auto_increment(); // it's too early here! BUG#20188
if (info->ignore && is_duplicate_key_error= table->file->is_fatal_error(error, 0);
!table->file->cannot_ignore_error(error, 0)) if (info->ignore && !is_duplicate_key_error)
goto ok_or_after_trg_err; goto ok_or_after_trg_err;
if ((int) (key_nr = table->file->get_dup_key(error)) < 0) 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; goto err;
} }
/* Read all columns for the row we are going to replace */ /* 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) ...@@ -1066,7 +1067,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
table->record[0]))) table->record[0])))
{ {
if (info->ignore && 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 ok_or_after_trg_err;
goto err; goto err;
} }
...@@ -1152,7 +1153,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) ...@@ -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]))) else if ((error=table->file->ha_write_row(table->record[0])))
{ {
if (!info->ignore || if (!info->ignore ||
table->file->cannot_ignore_error(error, HA_CHECK_DUPP)) table->file->is_fatal_error(error, HA_CHECK_DUPP))
goto err; goto err;
table->file->restore_auto_increment(); table->file->restore_auto_increment();
} }
......
...@@ -9354,7 +9354,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param, ...@@ -9354,7 +9354,7 @@ bool create_myisam_from_heap(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
/* copy row that filled HEAP table */ /* copy row that filled HEAP table */
if ((write_err=new_table.file->write_row(table->record[0]))) 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) !ignore_last_dupp_key_error)
goto err; goto err;
} }
...@@ -10777,7 +10777,7 @@ end_write(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)), ...@@ -10777,7 +10777,7 @@ end_write(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
join->found_records++; join->found_records++;
if ((error=table->file->write_row(table->record[0]))) 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; goto end;
if (create_myisam_from_heap(join->thd, table, &join->tmp_table_param, if (create_myisam_from_heap(join->thd, table, &join->tmp_table_param,
error,1)) error,1))
......
...@@ -6269,9 +6269,10 @@ copy_data_between_tables(TABLE *from,TABLE *to, ...@@ -6269,9 +6269,10 @@ copy_data_between_tables(TABLE *from,TABLE *to,
if ((error=to->file->ha_write_row((byte*) to->record[0]))) if ((error=to->file->ha_write_row((byte*) to->record[0])))
{ {
if (!ignore || 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); uint key_nr= to->file->get_dup_key(error);
if ((int) key_nr >= 0) if ((int) key_nr >= 0)
......
...@@ -65,7 +65,7 @@ bool select_union::send_data(List<Item> &values) ...@@ -65,7 +65,7 @@ bool select_union::send_data(List<Item> &values)
if ((error= table->file->ha_write_row(table->record[0]))) if ((error= table->file->ha_write_row(table->record[0])))
{ {
/* create_myisam_from_heap will generate error if needed */ /* 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)) create_myisam_from_heap(thd, table, &tmp_table_param, error, 1))
return 1; return 1;
} }
......
...@@ -542,13 +542,13 @@ int mysql_update(THD *thd, ...@@ -542,13 +542,13 @@ int mysql_update(THD *thd,
} }
} }
else if (!ignore || 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 If (ignore && error is ignorable) we don't have to
do anything; otherwise... 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 */ thd->fatal_error(); /* Other handler errors are fatal */
table->file->print_error(error,MYF(0)); table->file->print_error(error,MYF(0));
error= 1; error= 1;
...@@ -1424,13 +1424,13 @@ bool multi_update::send_data(List<Item> &not_used_values) ...@@ -1424,13 +1424,13 @@ bool multi_update::send_data(List<Item> &not_used_values)
{ {
updated--; updated--;
if (!ignore || 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 If (ignore && error == is ignorable) we don't have to
do anything; otherwise... 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 */ thd->fatal_error(); /* Other handler errors are fatal */
table->file->print_error(error,MYF(0)); table->file->print_error(error,MYF(0));
DBUG_RETURN(1); DBUG_RETURN(1);
...@@ -1459,7 +1459,7 @@ bool multi_update::send_data(List<Item> &not_used_values) ...@@ -1459,7 +1459,7 @@ bool multi_update::send_data(List<Item> &not_used_values)
/* Write row, ignoring duplicated updates to a row */ /* Write row, ignoring duplicated updates to a row */
if ((error= tmp_table->file->ha_write_row(tmp_table->record[0]))) 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, create_myisam_from_heap(thd, tmp_table,
tmp_table_param + offset, error, 1)) tmp_table_param + offset, error, 1))
{ {
...@@ -1583,7 +1583,7 @@ int multi_update::do_updates(bool from_send_error) ...@@ -1583,7 +1583,7 @@ int multi_update::do_updates(bool from_send_error)
table->record[0]))) table->record[0])))
{ {
if (!ignore || 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; goto err;
} }
updated++; updated++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment