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

Persistent table is ALLOWED to declare a FOREIGN KEY that REFERENCES a Global Temporary Table

    XMLWordPrintable

Details

    • Not for Release Notes

    Description

      MDEV-35915 CS 13.0.0 fcf14161a97ec5542a265d6f00a95264dbad4fa7 (Debug, Clang 18.1.3-11) Build 03/06/2026

       
      --source include/have_innodb.inc
       
      CREATE GLOBAL TEMPORARY TABLE parent (id INT PRIMARY KEY) ENGINE=InnoDB ON COMMIT PRESERVE ROWS;
      --echo # Expected ER_CANNOT_ADD_FOREIGN, but child table creation succeeds
      CREATE TABLE child (id INT PRIMARY KEY, pid INT, FOREIGN KEY(pid) REFERENCES parent (id)) ENGINE=InnoDB;
       
      INSERT INTO parent VALUES (1);
      --echo # The INSERT failed even though the parent table has rows with id = 1
      --error ER_NO_REFERENCED_ROW_2
      INSERT INTO child VALUES (10, 1);
       
      --echo # only NULL accepted:
      INSERT INTO child VALUES (10, NULL);
      SELECT * FROM child;
       
      
      

      Output

      CREATE GLOBAL TEMPORARY TABLE parent (id INT PRIMARY KEY) ENGINE=InnoDB ON COMMIT PRESERVE ROWS;
      # Expected ER_CANNOT_ADD_FOREIGN, but child table creation succeeds
      CREATE TABLE child (id INT PRIMARY KEY, pid INT, FOREIGN KEY(pid) REFERENCES parent (id)) ENGINE=InnoDB;
      INSERT INTO parent VALUES (1);
      # The INSERT failed even though the parent table has rows with id = 1
      INSERT INTO child VALUES (10, 1);
      ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`pid`) REFERENCES `parent` (`id`))
      # only NULL accepted:
      INSERT INTO child VALUES (10, NULL);
      SELECT * FROM child;
      id	pid
      10	NULL
      

      Attachments

        Issue Links

          Activity

            People

              nikitamalyavin Nikita Malyavin
              ramesh Ramesh Sivaraman
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0d
                  0d
                  Logged:
                  Time Spent - 0.5h
                  0.5h

                  Git Integration

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