Skip to content

Commit

Permalink
MDEV-32439 INSERT IGNORE on constraints result in ERROR rather than w…
Browse files Browse the repository at this point in the history
…arning

INSERT IGNORE had a pecular undocumented case that when one row was
inserted, there was an error rather than a warning.

As LOAD DATA IGNORE, UPDATE IGNORE, INSERT IGNORE SELECT, and INSERT
IGNORE VALUES (single row, for foreign key violation) all behave the same
way with a warning lets keep the behaviour normalized.

In compatibility, previously a error was generated, now a warning is
generated.

This behaviour is now consistent with MySQL-8.0 too.
  • Loading branch information
grooverdan committed Nov 14, 2023
1 parent b0379ea commit 9e457cb
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 10 deletions.
58 changes: 57 additions & 1 deletion mysql-test/main/check_constraint.result
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,61 @@ t1 CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t1;
#
# End of 10.4 tests
# MDEV-32439 INSERT IGNORE VALUES (one row) errors on constraint
#
CREATE TABLE t1 (v1 varchar(10), v2 varchar(10), constraint unequal check (v1 != v2));
INSERT IGNORE INTO t1 VALUES (1,1);
Warnings:
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
SHOW WARNINGS;
Level Code Message
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
INSERT IGNORE INTO t1 VALUES (1,2),(2,2);
Warnings:
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
SHOW WARNINGS;
Level Code Message
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
INSERT IGNORE INTO t1 VALUES (3,3),(4,4);
Warnings:
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
SHOW WARNINGS;
Level Code Message
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
SELECT * FROM t1;
v1 v2
1 2
DROP TABLE t1;
#
# MDEV-32439 INSERT IGNORE VALUES (one row) errors on constraint
#
CREATE TABLE t1 (v1 varchar(10), v2 varchar(10), constraint unequal check (v1 != v2));
INSERT IGNORE INTO t1 VALUES (1,1);
Warnings:
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
SHOW WARNINGS;
Level Code Message
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
INSERT IGNORE INTO t1 VALUES (1,2),(2,2);
Warnings:
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
SHOW WARNINGS;
Level Code Message
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
INSERT IGNORE INTO t1 VALUES (3,3),(4,4);
Warnings:
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
SHOW WARNINGS;
Level Code Message
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
Warning 4025 CONSTRAINT `unequal` failed for `test`.`t1`
SELECT * FROM t1;
v1 v2
1 2
DROP TABLE t1;
#
# End of 11.4 tests
#
30 changes: 29 additions & 1 deletion mysql-test/main/check_constraint.test
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,33 @@ show create table t1;
drop table t1;

--echo #
--echo # End of 10.4 tests
--echo # MDEV-32439 INSERT IGNORE VALUES (one row) errors on constraint
--echo #

CREATE TABLE t1 (v1 varchar(10), v2 varchar(10), constraint unequal check (v1 != v2));
INSERT IGNORE INTO t1 VALUES (1,1);
SHOW WARNINGS;
INSERT IGNORE INTO t1 VALUES (1,2),(2,2);
SHOW WARNINGS;
INSERT IGNORE INTO t1 VALUES (3,3),(4,4);
SHOW WARNINGS;
SELECT * FROM t1;
DROP TABLE t1;

--echo #
--echo # MDEV-32439 INSERT IGNORE VALUES (one row) errors on constraint
--echo #

CREATE TABLE t1 (v1 varchar(10), v2 varchar(10), constraint unequal check (v1 != v2));
INSERT IGNORE INTO t1 VALUES (1,1);
SHOW WARNINGS;
INSERT IGNORE INTO t1 VALUES (1,2),(2,2);
SHOW WARNINGS;
INSERT IGNORE INTO t1 VALUES (3,3),(4,4);
SHOW WARNINGS;
SELECT * FROM t1;
DROP TABLE t1;

--echo #
--echo # End of 11.4 tests
--echo #
9 changes: 8 additions & 1 deletion mysql-test/main/view.result
Original file line number Diff line number Diff line change
Expand Up @@ -1228,10 +1228,17 @@ drop table t1;
create table t1 (s1 int);
create view v1 as select * from t1 where s1 < 5 with check option;
insert ignore into v1 values (6);
ERROR 44000: CHECK OPTION failed `test`.`v1`
Warnings:
Warning 1369 CHECK OPTION failed `test`.`v1`
SHOW WARNINGS;
Level Code Message
Warning 1369 CHECK OPTION failed `test`.`v1`
insert ignore into v1 values (6),(3);
Warnings:
Warning 1369 CHECK OPTION failed `test`.`v1`
SHOW WARNINGS;
Level Code Message
Warning 1369 CHECK OPTION failed `test`.`v1`
select * from t1;
s1
3
Expand Down
5 changes: 3 additions & 2 deletions mysql-test/main/view.test
Original file line number Diff line number Diff line change
Expand Up @@ -1126,15 +1126,16 @@ drop view v2, v1;
drop table t1;

#
# inserting single value with check option failed always get error
# inserting single value with check option warns like 2 values
#
create table t1 (s1 int);
create view v1 as select * from t1 where s1 < 5 with check option;
#single value
-- error ER_VIEW_CHECK_FAILED
insert ignore into v1 values (6);
SHOW WARNINGS;
#several values
insert ignore into v1 values (6),(3);
SHOW WARNINGS;
select * from t1;
drop view v1;
drop table t1;
Expand Down
6 changes: 1 addition & 5 deletions sql/sql_insert.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1129,11 +1129,7 @@ bool mysql_insert(THD *thd, TABLE_LIST *table_list,
}
}

if ((res= table_list->view_check_option(thd,
(values_list.elements == 1 ?
0 :
ignore))) ==
VIEW_CHECK_SKIP)
if ((res= table_list->view_check_option(thd, ignore)) == VIEW_CHECK_SKIP)
continue;
else if (res == VIEW_CHECK_ERROR)
{
Expand Down

0 comments on commit 9e457cb

Please sign in to comment.