Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-37358

Coinstraints in DELETE statement should be evaluated per whole query (instead of per isolated row)

    XMLWordPrintable

Details

    • New Feature
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • Server
    • 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

          Activity

            People

              Unassigned Unassigned
              mv Michael Voříšek
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.