1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-29 00:08:14 +03:00

Bug#60196 / Bug#11831040

Setting lowercase_table_names to 2 on Windows causing Foreign Key problems

This problem was exposed by the fix for Bug#55222.  There was a codepath in dict0load.c,
dict_load_foreigns() that made sure the table name matched case sensitive in order to
load a referenced table into the dictionary as needed.  If an engine is rebooted which
accesses a table with foreign keys, and lower_case_table_names=2, then the table with
foreign keys will get an error when it is changed (insert/updated/delete).
Once the referenced tables are loaded into the dictionary cache by a select statement
on those tables, the same change would succeed because the affected code path would
not get followed.
This commit is contained in:
kevin.lewis@oracle.com
2011-03-07 09:42:07 -06:00
parent a3dfebf3e5
commit d072bb0d7f
4 changed files with 173 additions and 3 deletions

View File

@@ -0,0 +1,76 @@
DROP TABLE IF EXISTS Bug_60196_FK1 ;
DROP TABLE IF EXISTS Bug_60196_FK2 ;
DROP TABLE IF EXISTS Bug_60196 ;
CREATE TABLE `Bug_60196_FK1` (Primary_Key INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE `Bug_60196_FK2` (Primary_Key INT PRIMARY KEY) ENGINE=InnoDB;
CREATE TABLE `Bug_60196` (
FK1_Key INT NOT NULL,
FK2_Key INT NOT NULL,
PRIMARY KEY (FK2_Key, FK1_Key),
KEY FK1_Key (FK1_Key),
KEY FK2_Key (FK2_Key),
CONSTRAINT FK_FK1 FOREIGN KEY (FK1_Key)
REFERENCES Bug_60196_FK1 (Primary_Key)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT FK_FK2 FOREIGN KEY (FK2_Key)
REFERENCES Bug_60196_FK2 (Primary_Key)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB;
INSERT INTO Bug_60196_FK1 VALUES (1), (2), (3), (4), (5);
INSERT INTO Bug_60196_FK2 VALUES (1), (2), (3), (4), (5);
INSERT INTO Bug_60196 VALUES (1, 1);
INSERT INTO Bug_60196 VALUES (1, 2);
INSERT INTO Bug_60196 VALUES (1, 3);
INSERT INTO Bug_60196 VALUES (1, 99);
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`bug_60196`, CONSTRAINT `FK_FK2` FOREIGN KEY (`FK2_Key`) REFERENCES `Bug_60196_FK2` (`Primary_Key`) ON DELETE CASCADE ON UPDATE CASCADE)
INSERT INTO Bug_60196 VALUES (99, 1);
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`bug_60196`, CONSTRAINT `FK_FK1` FOREIGN KEY (`FK1_Key`) REFERENCES `Bug_60196_FK1` (`Primary_Key`) ON DELETE CASCADE ON UPDATE CASCADE)
SELECT * FROM bug_60196_FK1;
Primary_Key
1
2
3
4
5
SELECT * FROM bug_60196_FK2;
Primary_Key
1
2
3
4
5
SELECT * FROM bug_60196;
FK1_Key FK2_Key
1 1
1 2
1 3
# Stop master server
# Restart server.
#
# Try to insert more to the example table with foreign keys.
# Bug60196 causes the foreign key file not to be found after
# the resstart above.
#
SELECT * FROM Bug_60196;
FK1_Key FK2_Key
1 1
1 2
1 3
INSERT INTO Bug_60196 VALUES (2, 1);
INSERT INTO Bug_60196 VALUES (2, 2);
INSERT INTO Bug_60196 VALUES (2, 3);
SELECT * FROM Bug_60196;
FK1_Key FK2_Key
1 1
1 2
1 3
2 1
2 2
2 3
# Clean up.
DROP TABLE Bug_60196;
DROP TABLE Bug_60196_FK1;
DROP TABLE Bug_60196_FK2;