MDEV-32688 Add innodb_foreign_key_errors status variable#4631
MDEV-32688 Add innodb_foreign_key_errors status variable#4631y2kwak wants to merge 1 commit intoMariaDB:mainfrom
Conversation
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
|
|
| INSERT INTO parent VALUES (1), (2), (3); | ||
| INSERT INTO child VALUES (1, 1), (2, 2); | ||
| # Counter starts at 0 | ||
| SHOW GLOBAL STATUS LIKE 'innodb_foreign_key_errors'; |
There was a problem hiding this comment.
to ensure that it indeed starts at 0, please make sure to either explicitly reset it (as mtr sometimes uses a running server instance that matches the start parameters for the current tests) or make sure that the test is always run on a freshly started server.
I'd do the former: saves one needless restart and lots of mtr run time.
This is why some of the build bot hosts are failing on your test btw.
| INSERT INTO child_cascade VALUES (1, 1); | ||
| DELETE FROM grandparent WHERE id = 1; | ||
| ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`parent_cascade`, CONSTRAINT `1` FOREIGN KEY (`gp_id`) REFERENCES `grandparent` (`id`)) | ||
| # Counter after CASCADE chain failure |
There was a problem hiding this comment.
say what the value needs to be please. makes it easier to read and check.
| DROP TABLE parent_cascade; | ||
| DROP TABLE grandparent; | ||
| # Counter resets after restart | ||
| # restart |
There was a problem hiding this comment.
Also, please, fix the commit message: do not mention the license in it. And remove the "similar to ..." part: it's not relevant.
Description
Add a new status variable
innodb_foreign_key_errorsthat tracks the total number of foreign key constraint violations in InnoDB, similar toinnodb_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.testIt can also be tested manually.
Basing the PR against the correct MariaDB version
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.