Skip to content
/ server Public

MDEV-32688 Add innodb_foreign_key_errors status variable#4631

Open
y2kwak wants to merge 1 commit intoMariaDB:mainfrom
y2kwak:MDEV-32688
Open

MDEV-32688 Add innodb_foreign_key_errors status variable#4631
y2kwak wants to merge 1 commit intoMariaDB:mainfrom
y2kwak:MDEV-32688

Conversation

@y2kwak
Copy link
Contributor

@y2kwak y2kwak commented Feb 6, 2026

Description

Add a new status variable innodb_foreign_key_errors that tracks the total number of foreign key constraint violations in InnoDB, similar to innodb_deadlocks.

The counter increments for both child-side violations and parent-side violations. Counter resets to 0 on server restart.

Added test coverage in mysql-test/suite/innodb/t/foreign_key_errors.test.

How can this PR be tested?

Run the MTR test foreign_key_error.test

It can also be tested manually.

  • Count starts at 0
MariaDB [(none)]> SHOW GLOBAL STATUS LIKE 'innodb_foreign_key_errors';
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| Innodb_foreign_key_errors | 0     |
+---------------------------+-------+
1 row in set (0.001 sec)
  • Count increments after error
MariaDB [testdb]> INSERT INTO child VALUES (1, 999);
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`testdb`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))

MariaDB [testdb]> SHOW GLOBAL STATUS LIKE 'innodb_foreign_key_errors';
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| Innodb_foreign_key_errors | 1     |
+---------------------------+-------+
1 row in set (0.000 sec)

MariaDB [testdb]> UPDATE child SET parent_id = 999 WHERE id = 1;
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`testdb`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))

MariaDB [testdb]> SHOW GLOBAL STATUS LIKE 'innodb_foreign_key_errors';
+---------------------------+-------+
| Variable_name             | Value |
+---------------------------+-------+
| Innodb_foreign_key_errors | 2     |
+---------------------------+-------+
1 row in set (0.000 sec)

Basing the PR against the correct MariaDB version

  •  This is a new feature and the PR is based against the latest MariaDB development branch.

Copyright

All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.

Add a new status variable that tracks the total number of foreign key
constraint violations in InnoDB, similar to innodb_deadlocks.

The counter increments for both child-side violations (INSERT/UPDATE with
non-existent parent) and parent-side violations (DELETE/UPDATE parent with
existing children). Counter resets to 0 on server restart.

All new code of the whole pull request, including one or several files
that are either new files or modified ones, are contributed under the
BSD-new license
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants