[MDEV-26615] uuid() function on default column value can violate PK/Unique constrants Created: 2021-09-16  Updated: 2021-09-20  Resolved: 2021-09-16

Status: Closed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 10.3.31, 10.7.0
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Daniel Black Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None

Issue Links:
Problem/Incident
is caused by MDEV-4958 Adding datatype UUID Closed

 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.



 Comments   
Comment by Daniel Black [ 2021-09-16 ]

need to read the uuids closer. They are unique.

Generated at Thu Feb 08 09:46:39 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.