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

uuid() function on default column value can violate PK/Unique constrants

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • 10.3.31, 10.7.0
    • N/A
    • Server
    • None

    Description

      $ podman run --rm -d -e MARIADB_USER=bob -e MARIADB_PASSWORD=entry -e MARIADB_DATABASE=uuidtest -e MARIADB_RANDOM_ROOT_PASSWORD=1 --name mariadb-uuid  quay.io/mariadb-foundation/mariadb-devel:10.7-mdev-4958-uuid-amd64
       
       
      $ podman exec -ti mariadb-uuid mariadb -u bob -pentry uuidtest
      Welcome to the MariaDB monitor.  Commands end with ; or \g.
      Your MariaDB connection id is 3
      Server version: 10.7.0-MariaDB-MDEV-4958-uuid mariadb.org binary distribution
       
      Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
       
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
       
      MariaDB [uuidtest]> create table uuidtest ( id uuid primary key default (uuid()));
      Query OK, 0 rows affected (0.021 sec)
       
      MariaDB [uuidtest]> insert into uuidtest values (),(),();
      Query OK, 3 rows affected (0.004 sec)
      Records: 3  Duplicates: 0  Warnings: 0
       
      MariaDB [uuidtest]> select * from uuidtest;
      +--------------------------------------+
      | id                                   |
      +--------------------------------------+
      | 2ed904c4-16bc-11ec-a724-7e502e50dded |
      | 2ed90772-16bc-11ec-a724-7e502e50dded |
      | 2ed90913-16bc-11ec-a724-7e502e50dded |
      +--------------------------------------+
       
      MariaDB [uuidtest]> insert into uuidtest values ('2ed904c4-16bc-11ec-a724-7e502e50dded'),('2ed904c4-16bc-11ec-a724-7e502e50dded'),('2ed904c4-16bc-11ec-a724-7e502e50dded');
      ERROR 1062 (23000): Duplicate entry '2ed904c4-16bc-11ec-a724-7e502e50dded' for key 'PRIMARY'
      

      So the uuid is predicable on time and duplicate can result.

      https://dbfiddle.uk/?rdbms=mariadb_10.3&fiddle=11ff9431a36876d4ee7d6d3e7daa0c80

      Probably on 10.2 too.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              danblack Daniel Black
              Votes:
              0 Vote for this issue
              Watchers:
              1 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.