Details
-
New Feature
-
Status: Open (View Workflow)
-
Major
-
Resolution: Unresolved
-
None
-
None
Description
online repro: https://dbfiddle.uk/G9DrLGUu
minimal repro:
CREATE TABLE t ( |
id int NOT NULL, |
parent_id int, |
name varchar(64) NOT NULL, |
PRIMARY KEY (id), |
UNIQUE KEY (id), |
CONSTRAINT fk_parent FOREIGN KEY (parent_id) REFERENCES t(id) |
);
|
|
insert into t values |
(1, null, 'A'), |
(2, 1, 'B'), |
(3, 1, 'B'), |
(4, 4, 'C'); |
|
/* id=3 can be deleted and then id=1 */
|
delete from t where id = 3 or id = 1; |
// Cannot delete or update a parent row: a foreign key constraint fails |
// (`fiddle`.`t`, CONSTRAINT `fk_parent` FOREIGN KEY (`parent_id`) REFERENCES `t` (`id`)) |
|
/* id=4 can be deleted as it is cyclic to itself */
|
delete from t where id = 4; |
// Cannot delete or update a parent row: a foreign key constraint fails |
// (`fiddle`.`t`, CONSTRAINT `fk_parent` FOREIGN KEY (`parent_id`) REFERENCES `t` (`id`)) |
Evaluating constraints per whole query (instead of per isolated table row) would allow grouping delete queries in a single query making apps more performant.
Currently this is limitation of MySQL/MariaDB. Other major databases like PostgreSQL, Microsoft SQL Server or even Oracle do already support this feature.
I would be grateful if MariaDB can support constrations validation per whole query as well.
Attachments
Issue Links
- relates to
-
MDEV-26096 Constraints: support deferred constraints [WAS: Make the Unique index ONLY evaluate immediately before the commit (NOT after each UPDATE)]
-
- Open
-