mirror of
https://github.com/MariaDB/server.git
synced 2025-07-26 13:15:00 +02:00

Before MySQL 4.0.18, user-specified constraint names were ignored. Starting with MySQL 4.0.18, the specified constraint name was prepended with the schema name and '/'. Now we are transforming into a format where the constraint name is prepended with the dict_table_t::name and the impossible UTF-8 sequence 0xff. Generated constraint names will be ASCII decimal numbers. On upgrade, old FOREIGN KEY constraint names will be displayed without any schema name prefix. They will be updated to the new format on DDL operations. dict_foreign_t::sql_id(): Return the SQL constraint name without any schemaname/tablename\377 or schemaname/ prefix. row_rename_table_for_mysql(), dict_table_rename_in_cache(): Simplify the logic: Just rename constraints to the new format. dict_table_get_foreign_id(): Replaces dict_table_get_highest_foreign_id(). innobase_get_foreign_key_info(): Let my_error() refer to erroneous anonymous constraints as "(null)". row_delete_constraint(): Try to drop all 3 constraint name variants. Reviewed by: Thirunarayanan Balathandayuthapani Tested by: Matthias Leich
62 lines
3.3 KiB
Text
62 lines
3.3 KiB
Text
#
|
|
# BUG#22037930: INSERT IGNORE FAILS TO IGNORE
|
|
# FOREIGN KEY CONSTRAINT
|
|
# Setup.
|
|
CREATE TABLE t1 (fld1 INT PRIMARY KEY) ENGINE=INNODB;
|
|
CREATE TABLE t2 (fld2 INT, FOREIGN KEY (fld2) REFERENCES t1 (fld1))
|
|
ENGINE=INNODB;
|
|
INSERT INTO t1 VALUES(0);
|
|
INSERT INTO t2 VALUES(0);
|
|
# Without fix, an error is reported.
|
|
INSERT IGNORE INTO t2 VALUES(1);
|
|
Warnings:
|
|
Warning 1452 Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
|
|
UPDATE IGNORE t2 SET fld2=20 WHERE fld2=0;
|
|
UPDATE IGNORE t1 SET fld1=20 WHERE fld1=0;
|
|
# Test for multi update.
|
|
UPDATE IGNORE t1, t2 SET t2.fld2= t2.fld2 + 3;
|
|
UPDATE IGNORE t1, t2 SET t1.fld1= t1.fld1 + 3;
|
|
# Reports an error since IGNORE is not used.
|
|
INSERT INTO t2 VALUES(1);
|
|
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
|
|
UPDATE t2 SET fld2=20 WHERE fld2=0;
|
|
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
|
|
UPDATE t1 SET fld1=20 WHERE fld1=0;
|
|
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
|
|
UPDATE t1, t2 SET t2.fld2= t2.fld2 + 3;
|
|
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
|
|
UPDATE t1, t2 SET t1.fld1= t1.fld1 + 3;
|
|
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
|
|
DROP TABLE t2, t1;
|
|
#
|
|
# BUG#22037930: INSERT IGNORE FAILS TO IGNORE FOREIGN
|
|
# KEY CONSTRAINT
|
|
CREATE TABLE t1 (fld1 INT PRIMARY KEY) ENGINE= INNODB;
|
|
CREATE TABLE t2 (fld1 VARCHAR(10), fld2 INT NOT NULL,
|
|
CONSTRAINT fk FOREIGN KEY (fld2) REFERENCES t1(fld1)) ENGINE= INNODB;
|
|
# Without patch, reports incorrect error.
|
|
INSERT INTO t2 VALUES('abc', 2) ON DUPLICATE KEY UPDATE fld1= 'def';
|
|
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
|
|
REPLACE INTO t2 VALUES('abc', 2);
|
|
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
|
|
INSERT IGNORE INTO t2 VALUES('abc', 2) ON DUPLICATE KEY UPDATE fld1= 'def';
|
|
Warnings:
|
|
Warning 1452 Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`))
|
|
DROP TABLE t2, t1;
|
|
#
|
|
# MDEV-26433: assertion: table->get_ref_count() == 0 in dict0dict.cc
|
|
# line 1915
|
|
#
|
|
CREATE TEMPORARY TABLE v0 ( v1 TEXT ( 15 ) CHAR SET BINARY NOT NULL NOT NULL UNIQUE CHECK ( v1 ) ) REPLACE SELECT NULL AS v3 , 74 AS v2 ;
|
|
ERROR HY000: Field 'v1' doesn't have a default value
|
|
SET @@sql_mode='';
|
|
CREATE TEMPORARY TABLE t1 (i TEXT(15) NOT NULL DEFAULT '' UNIQUE CHECK (i)) engine=innodb
|
|
REPLACE SELECT NULL AS a;
|
|
ERROR 23000: CONSTRAINT `t1.i` failed for `test`.`t1`
|
|
SET @@sql_mode=DEFAULT;
|
|
CREATE TEMPORARY TABLE t1 (i TEXT(15) NOT NULL DEFAULT '' UNIQUE CHECK (i)) engine=innodb
|
|
REPLACE SELECT NULL AS a;
|
|
ERROR 22007: Truncated incorrect BOOLEAN value: ''
|
|
#
|
|
# End of 10.5 tests
|
|
#
|