Bug #71669 Inconsistence with RESTRICT and NO ACTION
Submitted: 11 Feb 2014 12:25 Modified: 24 Jul 2014 20:09
Reporter: Peter Laursen (Basic Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.537-35.1-log, 5.0.97, 5.1.74, 5.5.39, 5.6.21, 5.7.5 OS:Any
Assigned to: CPU Architecture:Any

[11 Feb 2014 12:25] Peter Laursen
Description:
(not sure about the category!)

I am aware that RESTRCIT adn NO ACTION are synonyms in MySQL In Foreign Key definitios as described at https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html

"
RESTRICT: Rejects the delete or update operation for the parent table. Specifying RESTRICT (or NO ACTION) is the same as omitting the ON DELETE or ON UPDATE clause. 

NO ACTION: A keyword from standard SQL. In MySQL, equivalent to RESTRICT. The MySQL Server rejects the delete or update operation for the parent table if there is a related foreign key value in the referenced table. Some database systems have deferred checks, and NO ACTION is a deferred check. In MySQL, foreign key constraints are checked immediately, so NO ACTION is the same as RESTRICT.
"

.. but they are handled inconsistently.

How to repeat:
Let us create tables:

CREATE TABLE `parent` (
`id` int(11) NOT NULL,
`txt` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `child` (
`id` int(11) NOT NULL,
`link` int(11) DEFAULT NULL,
`txt` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

After executing "ALTER TABLE `fktest`.`child` ADD CONSTRAINT `dummy` FOREIGN KEY (`link`) REFERENCES `fktest`.`parent`(`id`) ON UPDATE RESTRICT ON DELETE RESTRICT; "

. ."SHOW CREATE TABLE `child`;" returns 

CREATE TABLE `child` (
`id` int(11) NOT NULL,
`link` int(11) DEFAULT NULL,
`txt` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `dummy` (`link`),
CONSTRAINT `dummy` FOREIGN KEY (`link`) REFERENCES `parent` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

In other words the server simply ignores RESTRICT.

This contradicts the behavior with "NO ACTION". If I create teh same tables and next execute "ALTER TABLE `fktest`.`child` ADD CONSTRAINT `dummy` FOREIGN KEY (`link`) REFERENCES `fktest`.`parent`(`id`) ON UPDATE RESTRICT ON DELETE RESTRICT; " SHOW CREATE TABLE will return

CREATE TABLE `child` (
`id` int(11) NOT NULL,
`link` int(11) DEFAULT NULL,
`txt` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `dummy` (`link`),
CONSTRAINT `dummy` FOREIGN KEY (`link`) REFERENCES `parent` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8

(and same with "CASCADE" and "SET NULL")

However in I_S.REFERENTIAL_CONSTRAINTS, "RESTRICT does appear in UPDATE_RULE adn DELETE_RULE columns

Suggested fix:
Return the RESTRICT (or its synonym NO ACTION) keyword in SHOW CREATE TABLE. And ensure consistency between SHOW and I_S.
[11 Feb 2014 12:41] Peter Laursen
Sorry .. at the bottom I should have pasted another statement. Correct is 

This contradicts the behavior with "NO ACTION". If I create the same tables and next execute "ALTER TABLE `fktest`.`child` ADD CONSTRAINT `dummy` FOREIGN KEY (`link`) REFERENCES `fktest`.`parent`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION; " SHOW CREATE TABLE will return
.. etc.

(obviously)
[24 Jul 2014 20:09] Sveta Smirnova
Thank you for the report.

Verified as described.