Skip to content

Commit 24ac546

Browse files
committed
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
1 parent 9e826bf commit 24ac546

File tree

5 files changed

+11
-63
lines changed

5 files changed

+11
-63
lines changed

mysql-test/r/insert_innodb.result

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,11 @@ INSERT INTO t2 VALUES(0);
1111
INSERT IGNORE INTO t2 VALUES(1);
1212
Warnings:
1313
Warning 1452 Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
14-
Warning 1452 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)
1514
UPDATE IGNORE t2 SET fld2=20 WHERE fld2=0;
16-
Warnings:
17-
Warning 1452 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)
1815
UPDATE IGNORE t1 SET fld1=20 WHERE fld1=0;
19-
Warnings:
20-
Warning 1451 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)
2116
# Test for multi update.
2217
UPDATE IGNORE t1, t2 SET t2.fld2= t2.fld2 + 3;
23-
Warnings:
24-
Warning 1452 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)
2518
UPDATE IGNORE t1, t2 SET t1.fld1= t1.fld1 + 3;
26-
Warnings:
27-
Warning 1451 `test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)
2819
# Reports an error since IGNORE is not used.
2920
INSERT INTO t2 VALUES(1);
3021
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))

sql/handler.cc

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5463,28 +5463,3 @@ fl_create_iterator(enum handler_iterator_type type,
54635463
}
54645464
}
54655465
#endif /*TRANS_LOG_MGM_EXAMPLE_CODE*/
5466-
5467-
5468-
/**
5469-
Report a warning for FK constraint violation.
5470-
5471-
@param thd Thread handle.
5472-
@param table table on which the operation is performed.
5473-
@param error handler error number.
5474-
*/
5475-
void warn_fk_constraint_violation(THD *thd,TABLE *table, int error)
5476-
{
5477-
String str;
5478-
switch(error) {
5479-
case HA_ERR_ROW_IS_REFERENCED:
5480-
table->file->get_error_message(error, &str);
5481-
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
5482-
ER_ROW_IS_REFERENCED_2, str.c_ptr_safe());
5483-
break;
5484-
case HA_ERR_NO_REFERENCED_ROW:
5485-
table->file->get_error_message(error, &str);
5486-
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
5487-
ER_NO_REFERENCED_ROW_2, str.c_ptr_safe());
5488-
break;
5489-
}
5490-
}

sql/handler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@
335335
#define HA_CHECK_DUP_UNIQUE 2
336336
#define HA_CHECK_FK_ERROR 4
337337
#define HA_CHECK_DUP (HA_CHECK_DUP_KEY + HA_CHECK_DUP_UNIQUE)
338+
#define HA_CHECK_ALL (~0U)
338339

339340
enum legacy_db_type
340341
{
@@ -3110,6 +3111,4 @@ inline const char *table_case_name(HA_CREATE_INFO *info, const char *name)
31103111
return ((lower_case_table_names == 2 && info->alias) ? info->alias : name);
31113112
}
31123113

3113-
void warn_fk_constraint_violation(THD *thd, TABLE *table, int error);
3114-
31153114
#endif /* HANDLER_INCLUDED */

sql/sql_insert.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,9 +1609,10 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
16091609
else
16101610
table->file->insert_id_for_cur_row= insert_id_for_cur_row;
16111611
bool is_duplicate_key_error;
1612-
if (table->file->is_fatal_error(error, HA_CHECK_DUP | HA_CHECK_FK_ERROR))
1612+
if (table->file->is_fatal_error(error, HA_CHECK_ALL))
16131613
goto err;
1614-
is_duplicate_key_error= table->file->is_fatal_error(error, 0);
1614+
is_duplicate_key_error=
1615+
table->file->is_fatal_error(error, HA_CHECK_ALL & ~HA_CHECK_DUP);
16151616
if (!is_duplicate_key_error)
16161617
{
16171618
/*
@@ -1712,8 +1713,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
17121713
error != HA_ERR_RECORD_IS_THE_SAME)
17131714
{
17141715
if (info->ignore &&
1715-
!table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
1716-
HA_CHECK_FK_ERROR))
1716+
!table->file->is_fatal_error(error, HA_CHECK_ALL))
17171717
{
17181718
if (!(thd->variables.old_behavior &
17191719
OLD_MODE_NO_DUP_KEY_WARNINGS_WITH_IGNORE))
@@ -1845,7 +1845,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
18451845
{
18461846
DEBUG_SYNC(thd, "write_row_noreplace");
18471847
if (!info->ignore ||
1848-
table->file->is_fatal_error(error, HA_CHECK_DUP | HA_CHECK_FK_ERROR))
1848+
table->file->is_fatal_error(error, HA_CHECK_ALL))
18491849
goto err;
18501850
if (!(thd->variables.old_behavior &
18511851
OLD_MODE_NO_DUP_KEY_WARNINGS_WITH_IGNORE))
@@ -1866,9 +1866,6 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
18661866
my_safe_afree(key,table->s->max_unique_length,MAX_KEY_LENGTH);
18671867
if (!table->file->has_transactions())
18681868
thd->transaction.stmt.modified_non_trans_table= TRUE;
1869-
if (info->ignore &&
1870-
!table->file->is_fatal_error(error, HA_CHECK_FK_ERROR))
1871-
warn_fk_constraint_violation(thd, table, error);
18721869
DBUG_RETURN(trg_error);
18731870

18741871
err:

sql/sql_update.cc

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -774,27 +774,22 @@ int mysql_update(THD *thd,
774774
error= 0;
775775
}
776776
else if (!ignore ||
777-
table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
778-
HA_CHECK_FK_ERROR))
777+
table->file->is_fatal_error(error, HA_CHECK_ALL))
779778
{
780779
/*
781780
If (ignore && error is ignorable) we don't have to
782781
do anything; otherwise...
783782
*/
784783
myf flags= 0;
785784

786-
if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
787-
HA_CHECK_FK_ERROR))
785+
if (table->file->is_fatal_error(error, HA_CHECK_ALL))
788786
flags|= ME_FATALERROR; /* Other handler errors are fatal */
789787

790788
prepare_record_for_error_message(error, table);
791789
table->file->print_error(error,MYF(flags));
792790
error= 1;
793791
break;
794792
}
795-
else if (ignore && !table->file->is_fatal_error(error,
796-
HA_CHECK_FK_ERROR))
797-
warn_fk_constraint_violation(thd, table, error);
798793
}
799794

800795
if (table->triggers &&
@@ -1974,26 +1969,21 @@ int multi_update::send_data(List<Item> &not_used_values)
19741969
{
19751970
updated--;
19761971
if (!ignore ||
1977-
table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
1978-
HA_CHECK_FK_ERROR))
1972+
table->file->is_fatal_error(error, HA_CHECK_ALL))
19791973
{
19801974
/*
19811975
If (ignore && error == is ignorable) we don't have to
19821976
do anything; otherwise...
19831977
*/
19841978
myf flags= 0;
19851979

1986-
if (table->file->is_fatal_error(error, HA_CHECK_DUP_KEY |
1987-
HA_CHECK_FK_ERROR))
1980+
if (table->file->is_fatal_error(error, HA_CHECK_ALL))
19881981
flags|= ME_FATALERROR; /* Other handler errors are fatal */
19891982

19901983
prepare_record_for_error_message(error, table);
19911984
table->file->print_error(error,MYF(flags));
19921985
DBUG_RETURN(1);
19931986
}
1994-
else if (ignore && !table->file->is_fatal_error(error,
1995-
HA_CHECK_FK_ERROR))
1996-
warn_fk_constraint_violation(thd, table, error);
19971987
}
19981988
else
19991989
{
@@ -2266,15 +2256,11 @@ int multi_update::do_updates()
22662256
local_error != HA_ERR_RECORD_IS_THE_SAME)
22672257
{
22682258
if (!ignore ||
2269-
table->file->is_fatal_error(local_error, HA_CHECK_DUP_KEY |
2270-
HA_CHECK_FK_ERROR))
2259+
table->file->is_fatal_error(local_error, HA_CHECK_ALL))
22712260
{
22722261
err_table= table;
22732262
goto err;
22742263
}
2275-
else if (ignore && !table->file->is_fatal_error(local_error,
2276-
HA_CHECK_FK_ERROR))
2277-
warn_fk_constraint_violation(thd, table, local_error);
22782264
}
22792265
if (local_error != HA_ERR_RECORD_IS_THE_SAME)
22802266
updated++;

0 commit comments

Comments
 (0)