Bug #90669 | Information_schema referential_constraints problem | ||
---|---|---|---|
Submitted: | 27 Apr 2018 13:20 | Modified: | 14 Mar 2019 10:54 |
Reporter: | Emmanuel CARVIN | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Information schema | Severity: | S3 (Non-critical) |
Version: | 5.7.25 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[27 Apr 2018 13:20]
Emmanuel CARVIN
[27 Apr 2018 14:17]
Chiranjeevi Battula
Hello Emmanuel, Thank you for the bug report. Verified this behavior on MySQL Workbench in 8.0.11 version. Thanks, Chiranjeevi.
[27 Apr 2018 14:17]
Chiranjeevi Battula
Screenshot
Attachment: Bug_90669.PNG (image/png, text), 33.01 KiB.
[1 Nov 2018 7:11]
Erlend Dahl
Unfortunately we had trouble reproducing this issue based on the information given. Is it still a problem in 8.0.13? One theory is that it has been fixed by Bug#91110 Foreign key reference option RESTRICT ignored after mysqldump and reload.
[2 Dec 2018 1:00]
Bugs System
No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open".
[13 Feb 2019 16:10]
Emmanuel CARVIN
Hello, It is not really MySQL8 which has this problem but the version 5.7 also Here is an example of reproduction of this error. the problem is caused by "SET FOREIGN_KEY_CHECKS = 0;" wich is created foreign key with default option even if we specify "RESTRICT" CREATE DATABASE IF NOT EXISTS testmysql DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci; USE testmysql; CREATE TABLE `abonnement` ( `idabonnement` INT NOT NULL AUTO_INCREMENT, `code` VARCHAR(45) NULL DEFAULT NULL, PRIMARY KEY (`idabonnement`)) ENGINE = InnoDB DEFAULT CHARACTER SET = latin1 COLLATE = latin1_general_ci; CREATE TABLE `abonnementcustomer` ( `idabonnementcustomer` INT NOT NULL AUTO_INCREMENT, `idabonnement` INT NULL, `nom` VARCHAR(45) NULL, PRIMARY KEY (`idabonnementcustomer`)); SET FOREIGN_KEY_CHECKS = 0; INSERT INTO abonnement (`idabonnement`, `code`) VALUES (1, 'test'); INSERT INTO abonnementcustomer (`idabonnementcustomer`, `idabonnement`, `nom`) VALUES (1, 1, 'test'); ALTER TABLE `abonnementcustomer` ADD CONSTRAINT `fk_abonnementcustomer_1` FOREIGN KEY (`idabonnement`) REFERENCES `abonnement` (`idabonnement`) ON DELETE RESTRICT ON UPDATE RESTRICT ; SET FOREIGN_KEY_CHECKS = 1; SELECT OptForeignKey.constraint_name AS NomContrainte, OptForeignKey.table_name AS TableSource, (SELECT column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneSource, OptForeignKey.referenced_table_name AS TableReference, (SELECT referenced_column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneReference, OptForeignKey.update_rule AS OptionUpdate, OptForeignKey.delete_rule AS OptionDelete FROM information_schema.referential_constraints AS OptForeignKey WHERE OptForeignKey.constraint_schema = 'testmysql' AND OptForeignKey.table_name = 'abonnementcustomer' GROUP BY OptForeignKey.constraint_name;
[13 Feb 2019 17:09]
MySQL Verification Team
Please disregard my last comment.
[14 Mar 2019 10:44]
MySQL Verification Team
mysql [localhost:5725] {msandbox} ((none)) > mysql [localhost:5725] {msandbox} ((none)) > CREATE DATABASE IF NOT EXISTS testmysql DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci; Query OK, 1 row affected (0.00 sec) mysql [localhost:5725] {msandbox} ((none)) > mysql [localhost:5725] {msandbox} ((none)) > USE testmysql; Database changed mysql [localhost:5725] {msandbox} (testmysql) > `idabonnement` INT NOT NULL AUTO_INCREMENT, mysql [localhost:5725] {msandbox} (testmysql) > CREATE TABLE `abonnement` ( -> `idabonnement` INT NOT NULL AUTO_INCREMENT, -> `code` VARCHAR(45) NULL DEFAULT NULL, -> PRIMARY KEY (`idabonnement`)) -> ENGINE = InnoDB -> DEFAULT CHARACTER SET = latin1 -> COLLATE = latin1_general_ci; Query OK, 0 rows affected (0.01 sec) mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > CREATE TABLE `abonnementcustomer` ( -> `idabonnementcustomer` INT NOT NULL AUTO_INCREMENT, -> `idabonnement` INT NULL, -> `nom` VARCHAR(45) NULL, -> PRIMARY KEY (`idabonnementcustomer`)); Query OK, 0 rows affected (0.01 sec) mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > SET FOREIGN_KEY_CHECKS = 0; Query OK, 0 rows affected (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) > INSERT INTO abonnement (`idabonnement`, `code`) VALUES (1, 'test'); Query OK, 1 row affected (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) > INSERT INTO abonnementcustomer (`idabonnementcustomer`, `idabonnement`, `nom`) VALUES (1, 1, 'test'); Query OK, 1 row affected (0.01 sec) mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > ALTER TABLE `abonnementcustomer` -> ADD CONSTRAINT `fk_abonnementcustomer_1` -> FOREIGN KEY (`idabonnement`) -> REFERENCES `abonnement` (`idabonnement`) -> ON DELETE RESTRICT -> ON UPDATE RESTRICT -> ; Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > SET FOREIGN_KEY_CHECKS = 1; Query OK, 0 rows affected (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) > SELECT OptForeignKey.constraint_name AS NomContrainte, -> OptForeignKey.table_name AS TableSource, -> (SELECT column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneSource, -> OptForeignKey.referenced_table_name AS TableReference, -> (SELECT referenced_column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneReference, -> OptForeignKey.update_rule AS OptionUpdate, -> OptForeignKey.delete_rule AS OptionDelete -> -> FROM information_schema.referential_constraints AS OptForeignKey -> -> WHERE OptForeignKey.constraint_schema = 'testmysql' -> AND OptForeignKey.table_name = 'abonnementcustomer' -> GROUP BY OptForeignKey.constraint_name; ERROR 1055 (42000): Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'information_schema.OptForeignKey.REFERENCED_TABLE_NAME' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by mysql [localhost:5725] {msandbox} (testmysql) > select @@sql_mode; +-------------------------------------------------------------------------------------------------------------------------------------------+ | @@sql_mode | +-------------------------------------------------------------------------------------------------------------------------------------------+ | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION | +-------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) > set sql_mode=''; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) > SELECT OptForeignKey.constraint_name AS NomContrainte, -> OptForeignKey.table_name AS TableSource, -> (SELECT column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneSource, -> OptForeignKey.referenced_table_name AS TableReference, -> (SELECT referenced_column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneReference, -> OptForeignKey.update_rule AS OptionUpdate, -> OptForeignKey.delete_rule AS OptionDelete -> -> FROM information_schema.referential_constraints AS OptForeignKey -> -> WHERE OptForeignKey.constraint_schema = 'testmysql' -> AND OptForeignKey.table_name = 'abonnementcustomer' -> GROUP BY OptForeignKey.constraint_name; +-------------------------+--------------------+---------------+----------------+------------------+--------------+--------------+ | NomContrainte | TableSource | ColonneSource | TableReference | ColonneReference | OptionUpdate | OptionDelete | +-------------------------+--------------------+---------------+----------------+------------------+--------------+--------------+ | fk_abonnementcustomer_1 | abonnementcustomer | NULL | abonnement | NULL | NO ACTION | NO ACTION | +-------------------------+--------------------+---------------+----------------+------------------+--------------+--------------+ 1 row in set (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) >
[14 Mar 2019 10:48]
MySQL Verification Team
mysql [localhost:5725] {msandbox} (mysql) > CREATE DATABASE IF NOT EXISTS testmysql DEFAULT CHARACTER SET latin1 COLLATE latin1_general_ci; Query OK, 1 row affected (0.00 sec) mysql [localhost:5725] {msandbox} (mysql) > mysql [localhost:5725] {msandbox} (mysql) > USE testmysql; `idabonnementcustomer` INT NOT NULL AUTO_INCREMENT, `idabonnement` INT NULL, `nom` VARCHAR(45) NULL, PRIMARY KEY (`idabonnementcustomer`)); INSERT INTO abonnement (`idabonnement`, `code`) VALUES (1, 'test'); INSERT INTO abonnementcustomer (`idabonnementcustomer`, `idabonnement`, `nom`) VALUES (1, 1, 'test'); ALTER TABLE `abonnementcustomer` ADD CONSTRAINT `fk_abonnementcustomer_1` FOREIGN KEY (`idabonnement`) REFERENCES `abonnement` (`idabonnement`) ON DELETE RESTRICT ON UPDATE RESTRICT ; SELECT OptForeignKey.constraint_name AS NomContrainte, OptForeignKey.table_name AS TableSource, (SELECT column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneSource, OptForeignKey.referenced_table_name AS TableReference, (SELECT referenced_column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneReference, OptForeignKey.update_rule AS OptionUpdate, OptForeignKey.delete_rule AS OptionDelete FROM information_schema.referential_constraints AS OptForeignKey WHERE OptForeignKey.constraint_schema = 'testmysql' AND OptForeignKey.table_name = 'abonnementcustomer' GROUP BY OptForeignKey.constraint_name; Database changed mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > SET FOREIGN_KEY_CHECKS = 1; Query OK, 0 rows affected (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > CREATE TABLE `abonnement` ( -> `idabonnement` INT NOT NULL AUTO_INCREMENT, -> `code` VARCHAR(45) NULL DEFAULT NULL, -> PRIMARY KEY (`idabonnement`)) -> ENGINE = InnoDB -> DEFAULT CHARACTER SET = latin1 -> COLLATE = latin1_general_ci; Query OK, 0 rows affected (0.01 sec) mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > CREATE TABLE `abonnementcustomer` ( -> `idabonnementcustomer` INT NOT NULL AUTO_INCREMENT, -> `idabonnement` INT NULL, -> `nom` VARCHAR(45) NULL, -> PRIMARY KEY (`idabonnementcustomer`)); Query OK, 0 rows affected (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > INSERT INTO abonnement (`idabonnement`, `code`) VALUES (1, 'test'); Query OK, 1 row affected (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) > INSERT INTO abonnementcustomer (`idabonnementcustomer`, `idabonnement`, `nom`) VALUES (1, 1, 'test'); Query OK, 1 row affected (0.00 sec) mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > ALTER TABLE `abonnementcustomer` -> ADD CONSTRAINT `fk_abonnementcustomer_1` -> FOREIGN KEY (`idabonnement`) -> REFERENCES `abonnement` (`idabonnement`) -> ON DELETE RESTRICT -> ON UPDATE RESTRICT -> ; Query OK, 1 row affected (0.06 sec) Records: 1 Duplicates: 0 Warnings: 0 mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > mysql [localhost:5725] {msandbox} (testmysql) > SELECT OptForeignKey.constraint_name AS NomContrainte, -> OptForeignKey.table_name AS TableSource, -> (SELECT column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneSource, -> OptForeignKey.referenced_table_name AS TableReference, -> (SELECT referenced_column_name FROM information_schema.key_column_usage WHERE constraint_schema = 'rebelle_prod' AND table_name = '001abonnementclient' AND constraint_name = OptForeignKey.constraint_name LIMIT 1) AS ColonneReference, -> OptForeignKey.update_rule AS OptionUpdate, -> OptForeignKey.delete_rule AS OptionDelete -> -> FROM information_schema.referential_constraints AS OptForeignKey -> -> WHERE OptForeignKey.constraint_schema = 'testmysql' -> AND OptForeignKey.table_name = 'abonnementcustomer' -> GROUP BY OptForeignKey.constraint_name; +-------------------------+--------------------+---------------+----------------+------------------+--------------+--------------+ | NomContrainte | TableSource | ColonneSource | TableReference | ColonneReference | OptionUpdate | OptionDelete | +-------------------------+--------------------+---------------+----------------+------------------+--------------+--------------+ | fk_abonnementcustomer_1 | abonnementcustomer | NULL | abonnement | NULL | RESTRICT | RESTRICT | +-------------------------+--------------------+---------------+----------------+------------------+--------------+--------------+ 1 row in set (0.01 sec) mysql [localhost:5725] {msandbox} (testmysql) >
[14 Mar 2019 10:54]
MySQL Verification Team
- changed version to 5.7.25 - changed os to any (reproduced on linux) - changed severity to S3 (I disagree this is "critical") I'm verifying the bug for 5.7.25 (cannot reproduce this on 8.0.15) Thanks for report and a test case Bogdan
[6 Dec 2021 16:47]
Jordan Spivack
Confirmed that this exact behavior is happening with me when restoring DB with MySQL 8.0.22