Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Not a Bug
-
10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL)
-
None
Description
A replace from file of duplicated values into ucs2-encoded referencing field fails:
--source include/have_innodb.inc
|
|
create table t1 ( |
pk int primary key, |
f char(10) character set ucs2, |
key(f) |
) engine=innodb;
|
|
create table t2 ( |
pk int primary key, |
f13 char(10) character set ucs2 |
) engine=innodb;
|
|
set foreign_key_checks = off; |
alter table t2 add foreign key (f13) references t1 (f) on delete set null; |
set foreign_key_checks = on; |
|
insert into t1 values (1,'q'); |
insert into t2(pk, f13) values (1, 'q'), (2, 'q'); |
|
select * from t2 into outfile 't2.data'; |
|
load data infile 't2.data' replace into table t2; |
# cleanup
|
drop table t2, t1; |
10.3 c562ccf796c085211461386510ea5f7a8137cb96 |
mysqltest: At line 26: query 'load data infile 't2.data' replace |
into table t2' failed: 1452: Cannot add or update a child row: |
a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` |
FOREIGN KEY (`f13`) REFERENCES `t1` (`f`) ON DELETE SET NULL) |
Expected behavior: no error. Note that if a foreign key is added during CREATE TABLE, LOAD DATA does not fail:
create table t1 ( |
pk int primary key, |
f char(10) character set ucs2, |
key(f) |
) engine=innodb;
|
|
create table t2 ( |
pk int primary key, |
f13 char(10) character set ucs2 references t1 (f) on delete set null |
) engine=innodb;
|
|
insert into t1 values (1,'q'); |
insert into t2(pk, f13) values (1, 'q'), (2, 'q'); |
|
select * from t2 into outfile 't2.data'; |
|
load data infile 't2.data' replace into table t2; |
# cleanup
|
drop table t2, t1; |
Attachments
Issue Links
- blocks
-
MDEV-15990 REPLACE on a precise-versioned table returns duplicate key error (ER_DUP_ENTRY)
-
- Stalled
-
- relates to
-
MDEV-18879 WITH SYSTEM VERSIONING and FOREIGN KEY can insert a corrupted record
-
- Closed
-
-
MDEV-20812 Unexpected ER_ROW_IS_REFERENCED_2 or server crash in row_ins_foreign_report_err upon DELETE from versioned table with FK
-
- Closed
-
This issue is found during fixing of MDEV-15990. After i left only one execution branch for system versioning in replace (the one that corresponds to having triggers case), it started failing.
Since REPLACE on table with FK added on CREATE works fine, i conclude that the problem is not a file encoding.
With trigger actions logged like this:
) engine=innodb;
) engine=innodb;
--error 1452
# cleanup
We'll have a result
select * from log;
id s
1 1 q
2 1 q
The first row is BEFORE INSERT log, the second is BEFORE DELETE.
Insert detects duplicate correctly, then Delete, presumably, correctly deletes. After that, Insert is retried and is failed with ER_NO_REFERENCED_ROW_2.
So, innodb matched against duplicate correctly, but did incorrectly match against child row.