1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-15461 Check Constraints with binary logging makes insert inconsistent

Problem was that verify_constraints() didn't check if
there was an error as part of evaluating constraints
(can happen in strict mode).

In one-row-insert the error was ignored when using
binary logging as binary logging clear errors if insert
succeeded. In multi-row-insert the error was noticed
for the second row.

After this fix one will get an error for both one and
multi-row inserts if the constraints generates a warning
in strict mode.
This commit is contained in:
Monty
2018-05-15 17:02:08 +03:00
parent 0e296947db
commit 4ab180ad5e
3 changed files with 83 additions and 3 deletions

View File

@ -156,3 +156,44 @@ create table t1 (id int auto_increment primary key, datecol datetime, check (dat
insert into t1 (datecol) values (now());
insert into t1 (datecol) values (now());
drop table t1;
CREATE TABLE t1 (
EmployeeID SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
FirstName VARCHAR(30) NOT NULL CHECK (CHAR_LENGTH(FirstName > 2))
);
INSERT INTO t1 VALUES (NULL, 'Ken');
ERROR 22007: Truncated incorrect DOUBLE value: 'Ken'
SHOW WARNINGS;
Level Code Message
Error 1292 Truncated incorrect DOUBLE value: 'Ken'
Error 4025 CONSTRAINT `FirstName` failed for `test`.`t1`
INSERT INTO t1 VALUES (NULL, 'Ken'),(NULL, 'Brian');
ERROR 22007: Truncated incorrect DOUBLE value: 'Ken'
SHOW WARNINGS;
Level Code Message
Error 1292 Truncated incorrect DOUBLE value: 'Ken'
Error 4025 CONSTRAINT `FirstName` failed for `test`.`t1`
INSERT IGNORE INTO t1 VALUES (NULL, 'Ken');
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'Ken'
INSERT IGNORE INTO t1 VALUES (NULL, 'Ken'),(NULL, 'Brian');
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'Ken'
Warning 1292 Truncated incorrect DOUBLE value: 'Brian'
set sql_mode="";
INSERT INTO t1 VALUES (NULL, 'Ken');
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'Ken'
INSERT INTO t1 VALUES (NULL, 'Ken'),(NULL, 'Brian');
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'Ken'
Warning 1292 Truncated incorrect DOUBLE value: 'Brian'
set sql_mode=default;
select * from t1;
EmployeeID FirstName
1 Ken
2 Ken
3 Brian
4 Ken
5 Ken
6 Brian
drop table t1;