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

Self-referencing table produces "Got error 193" from InnoDB on cascading DELETE

    XMLWordPrintable

Details

    Description

      CREATE TABLE t (c1 INT KEY,c2 INT,FOREIGN KEY(c2) REFERENCES t (c1) ON DELETE CASCADE) ENGINE=InnoDB;
      INSERT INTO t VALUES (0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
      DELETE FROM t;
      

      Leads to:

      11.5.0 e4afa610539ae01164485554e2de839bea9de816 (Debug)

      11.5.0-dbg>CREATE TABLE t (c1 INT KEY,c2 INT,FOREIGN KEY(c2) REFERENCES t (c1) ON DELETE CASCADE) ENGINE=InnoDB;
      Query OK, 0 rows affected (0.012 sec)
       
      11.5.0-dbg>INSERT INTO t VALUES (0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),(8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
      Query OK, 16 rows affected (0.004 sec)
      Records: 16  Duplicates: 0  Warnings: 0
       
      11.5.0-dbg>DELETE FROM t;
      ERROR 1296 (HY000): Got error 193 '`test`.`t`, CONSTRAINT `t_ibfk_1` FOREIGN KEY (`c2`) REFERENCES `t` (`c1`) ON DELETE CASCADE' from InnoDB
      

      11.5.0 e4afa610539ae01164485554e2de839bea9de816 (Debug)

      2024-06-15 14:57:23 4 [ERROR] InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15. Please drop excessive foreign constraints and try again
      

      If the "max depth of 15" self-referencing error is not considered to be a bug, then we can improve the CLI error.

      Attachments

        Issue Links

          Activity

            People

              marko Marko Mäkelä
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.