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

FOREIGN KEY clause in CREATE TABLE ... ENGINE=DuckDB is silently accepted without any error or warning

    XMLWordPrintable

Details

    • Can result in unexpected behaviour

    Description

      FOREIGN KEY clause in CREATE TABLE ... ENGINE=DuckDB is silently accepted without any error or warning. However, the foreign key is not actually created as a constraint. Instead, it is silently converted into a plain secondary KEY (index) on the referencing column, and SHOW CREATE TABLE does not show that a FOREIGN KEY was specified.

      Test case

      INSTALL SONAME 'ha_duckdb';
      CREATE TABLE parent (id INT PRIMARY KEY) ENGINE=DuckDB;
      CREATE TABLE child (id INT PRIMARY KEY, parent_id INT, FOREIGN KEY (parent_id) REFERENCES parent(id)) ENGINE=DuckDB;
      SHOW CREATE TABLE child;
      SHOW WARNINGS;
      INSERT INTO child VALUES (1, 999);
      SELECT * FROM child;
      

      CLI Output

      13.1.0-dbg>INSTALL SONAME 'ha_duckdb';
       
      Query OK, 0 rows affected (1.023 sec)
       
      13.1.0-dbg>CREATE TABLE parent (id INT PRIMARY KEY) ENGINE=DuckDB;
      Query OK, 0 rows affected (0.030 sec)
       
      13.1.0-dbg>CREATE TABLE child (id INT PRIMARY KEY, parent_id INT, FOREIGN KEY (parent_id) REFERENCES parent(id)) ENGINE=DuckDB;
      Query OK, 0 rows affected (0.022 sec)
       
      13.1.0-dbg>SHOW CREATE TABLE child;
      +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                                                                                                    |
      +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | child | CREATE TABLE `child` (
        `id` int(11) NOT NULL,
        `parent_id` int(11) DEFAULT NULL,
        PRIMARY KEY (`id`),
        KEY `parent_id` (`parent_id`)
      ) ENGINE=DUCKDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
      +-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      1 row in set (0.000 sec)
       
      13.1.0-dbg>SHOW WARNINGS;
      Empty set (0.000 sec)
       
      13.1.0-dbg>INSERT INTO child VALUES (1, 999);
      Query OK, 1 row affected (0.044 sec)
       
      13.1.0-dbg>SELECT * FROM child;
      +----+-----------+
      | id | parent_id |
      +----+-----------+
      |  1 |       999 |
      +----+-----------+
      1 row in set (0.034 sec)
       
      13.1.0-dbg>
      

      Attachments

        Issue Links

          Activity

            People

              drrtuy Roman
              ramesh Ramesh Sivaraman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

                  Estimated:
                  Original Estimate - 0d
                  0d
                  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.