Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
10.5.27, 10.6.20, 10.11.10, 11.2.6, 11.4.4
Description
After upgrading to v10.11.10 creation of a foreign key failed with no information in engine innodb status. The same keys are allowed in 10.11.9 and below.
reproducer SQL:
CREATE TABLE `a` (
|
`a_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
`a_p_id` int(10) unsigned DEFAULT NULL,
|
PRIMARY KEY (`a_id`),
|
FOREIGN KEY (`a_p_id`) REFERENCES `a` (`a_id`)
|
) ENGINE=InnoDBa
|
|
|
CREATE TABLE `b` (
|
`b_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
`b_p_id` int(10) unsigned DEFAULT NULL,
|
PRIMARY KEY (`b_id`),
|
FOREIGN KEY (`b_p_id`) REFERENCES `b` (`b_id`)
|
) ENGINE=InnoDB
|
|
|
CREATE TABLE `b_a` (
|
`b_id` int(10) unsigned NOT NULL,
|
`a_p_id` int(10) unsigned NOT NULL,
|
`a_id` int(10) unsigned DEFAULT NULL,
|
PRIMARY KEY (`b_id`,`a_p_id`),
|
FOREIGN KEY (`b_id`) REFERENCES `b` (`b_id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
FOREIGN KEY (`a_p_id`, `a_id`) REFERENCES `a` (`a_p_id`, `a_id`) ON UPDATE CASCADE
|
) ENGINE=InnoDB
|
Changing the table b_a latest foreign key to "on delete cascade" does allow the table to be created, but that is not what I want to archieve.
Attachments
Issue Links
- is caused by
-
MDEV-34392 modification of the column fails to check foreign key constraint
-
- Closed
-
The column a.a_id is defined as NOT NULL, while b_a.a_id allows NULL values. It has been a while since I looked at FOREIGN KEY constraints, but it seems to me that the ON UPDATE CASCADE this way around should be allowed. If it were the other way around (the parent table does not allow NULL values but the child table column does not), then it would seem to me that ON UPDATE CASCADE can potentially be incorrect (trying to update a NOT NULL column to the NULL value).
thiru, can you please investigate this? Did
MDEV-34392get something wrong?