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

Foreign keys don't work with UNIQUE()

Details

    Description

      > create table ss (id integer primary key, struct TEXT);
      > create table mm (id integer primary key, sss integer NOT null references ss(id), name TEXT, UNIQUE(sss, name));
      ERROR 1005 (HY000): Can't create table `clang_struct`.`mm` (errno: 150 "Foreign key constraint is incorrectly formed")
      > SHOW ENGINE INNODB STATUS;
      ...
      LATEST FOREIGN KEY ERROR
      ------------------------
      2025-02-14 09:29:24 0x7f3ab01ff6c0 Error in foreign key constraint of table `clang_struct`.`mm`:
      Create  table `clang_struct`.`mm` with foreign key (sss) constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns.------------
      > show index from ss;
      +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
      | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Ignored |
      +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
      | ss    |          0 | PRIMARY  |            1 | id          | A         |           0 |     NULL | NULL   |      | BTREE      |         |               | NO      |
      +-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+
      ------------------------
      

      This looks like a bug. If I remove UNIQUE(), it works.

      Attachments

        Issue Links

          Activity

            jirislaby Jiri Slaby added a comment -

            mariadb:11.7-rc from docker (e544e5936f26) behaves the same.

            jirislaby Jiri Slaby added a comment - mariadb:11.7-rc from docker (e544e5936f26) behaves the same.

            Thanks for the report.
            This bug was fixed in the scope of MDEV-33658. 11.6 does not have the fix as it is already EOL, but all of 10.5.28, 10.6.21, 10.11.11, 11.4.5, 11.7.2 do.

            elenst Elena Stepanova added a comment - Thanks for the report. This bug was fixed in the scope of MDEV-33658 . 11.6 does not have the fix as it is already EOL, but all of 10.5.28, 10.6.21, 10.11.11, 11.4.5, 11.7.2 do.

            People

              Unassigned Unassigned
              jirislaby Jiri Slaby
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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