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

Implement DISTINCT and NOT DISTINCT for unique NULL handling

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • None

    Description

      In MariaDB, unique indexes permit duplicate NULLs.

      CREATE TABLE t2 (
          a int,
          b int,
          c int,
          UNIQUE (a, b, c) 
      );
       
      INSERT INTO t1 VALUES (1, NULL, NULL);
      INSERT INTO t1 VALUES (1, NULL, NULL);
       
      SELECT * FROM t1;
      +------+------+------+
      | a    | b    | c    |
      +------+------+------+
      |    1 | NULL | NULL |
      |    1 | NULL | NULL |
      +------+------+------+
      

      Previously, the SQL standard has not been clear about the behaviour, leaving it to be implemented in multiple ways. For example, SQL Server does not permit the second row to be inserted, while PostgreSQL does.

      Now, with the SQL 2023 standard, the behaviour is made explicit:

      CREATE TABLE t2 (
          a int,
          b int,
          c int,
          UNIQUE NULLS DISTINCT (a, b, c)
      );
      

      allows the duplicate NULL to be inserted, while

      CREATE TABLE t3 (
          a int,
          b int,
          c int,
          UNIQUE NULLS NOT DISTINCT (a, b, c)
      );
      

      does not.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              greenman Ian Gilfillan
              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.