[MDEV-6445] UUID column type addition for distributed systems Created: 2014-07-15  Updated: 2020-05-05  Resolved: 2016-08-01

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Fix Version/s: 10.2.1

Type: Task Priority: Minor
Reporter: Anders Karlsson Assignee: Michael Widenius
Resolution: Fixed Votes: 5
Labels: None

Issue Links:
Blocks
blocks MDEV-9519 Start Slave on a Galera should error ... Closed
PartOf
includes MDEV-9832 Improved last_insert_id() Closed
includes MDEV-10203 Enable Multi Master Galera Without PK... Open
includes MDEV-10205 Lack of UUID sequence forcing bad imp... Open
Relates
relates to MDEV-10134 Add full support for DEFAULT Closed

 Description   

Feature request:
The AUTO_INCREMENT field attribute has some attributes that are true in some cases, and not in others:

  • The value is unique
  • The value in incremented in sequence
  • The value is incremented without "gaps" in the sequence

The two last of these attributes are no longer always true. In addition, to keep the value unique one has to resort to using auto_increment_increment and auto_increment_offset, which will break the last of the assumptions above and when using a distributed system, classic Replication or Galera, then even the second one breaks. But these settings are still necessary to ensure uniqueness in a distributed system.

So the idea then is to, in addition to AUTO_INCREMENT I suggest we add a UUID column attribute. As for an INSERT, this would be the same as using UUID() for the column in the insert statement, but having this as a column attribute has several advantages. Compared to AUTO_INCREMENT there are also many advantages, such as avoiding at AUTO_INCREMENT mutex locks. In addition, having this as a column attribute would be a declarative, so the schema documents the column attribute properly. To make this work, we need to add a mysql_last_uuid() function and a LAST_UUID SQL functioon added.

I could see this having some additional features, such as:

  • Having this attribute assume a specific datatype, so that the type need not be explicitly specified..
  • Not allowing the value in a column with this attribute to be updated or inserted with anything but NULL, which will generate a new UUID.
  • Allowing a UUID_SHORT in addition to a UUID column attribute.
  • Automatic compacting of the UUID value (remove the dashes etc).

A drawback of this schema compared to AUTO_INCREMENT is that this will consume some more space in the specified column, but 16 bytes (8 bytes of we use UUID_SHORT) when the dashes are removed isn't so bad. The advantages not having to deal with the auto_increment_xxx settings, in particular when new nodes are added to the cluster, should outweigh this,



 Comments   
Comment by Anders Karlsson [ 2014-07-16 ]

An added benefit of using a UUID instead of some AUTO_INCREMENT is that in a distributed system, using Galera or Replication, data can be migrated between nodes and there is no data that ties or identifies a row to a specific server.

Comment by Sergei Golubchik [ 2014-07-21 ]

This looks like a duplicate of MDEV-4958.

Comment by Anders Karlsson [ 2014-07-21 ]

There is an overlap, but not a duplicate. What I suggest though is that automatic generation of a UUID is added and that semantics are such that only a proper UUID can be inserted and that it is always generated, so in the case of an INSERT and UPDATE, NULL always has to be passed if the value is to be updated. To support this, the proposed SQL and API functions for retrieving the last generated UUID has to be added.

Comment by Sergei Golubchik [ 2014-07-22 ]

Indeed, thanks for the clarification

Comment by Sergei Golubchik [ 2016-07-28 ]

Now, when one can specify DEFAULT UUID() for any column is this feature still necessary?

Comment by VAROQUI Stephane [ 2016-07-28 ]

Hello Sergei,

Is the value for last_insert_id , the PK or UNIQUE KEY default or always auto increment ?
see
MDEV-10014
MDEV-10422

/svar

Comment by Sergei Golubchik [ 2016-07-28 ]

last_insert_id is for auto increment only. INSERT ... RETURNING is a separate task

Comment by Daniël van Eeden [ 2016-07-28 ]

A column type could still be a good idea:

  • output formatting (shows uuid as string, but stores in a binary format)
  • rearange the uuid to make it increasing when on the same machine (put the timestamp in the end in reverse order) to be friendlier for B-Tree storage.
  • maybe do something smart with secondary indexes, don't put the mostly-static part (when running on one machine) in de index?
Comment by VAROQUI Stephane [ 2016-07-28 ]

dveeden that looks like existing UUID_SHORT and it should work the same !

serg without a way to fetch what was inserted it make this feature less attractive .The requirement that the field is facing today, is sometime to get read of auto increment. I appreciate the good step forward still , but will not make some of our clients move to 10.2. I will continue living with ugly triggers and ROW base login.

Can the DEFAULT overwrite
the auto_increment defining both on the same column , in such case teh last_isert_id would return what default is picked ?

Comment by Sergei Golubchik [ 2016-07-28 ]

dveeden, UUID column type is MDEV-4958. This issue is about auto-setting it to the new uuid() value, much like auto increment works. And I suggest that this special auto-setting treatment for columns of UUID type is no longer needed, because one can write DEFAULT UUID(). UUID column type itself it still useful, yes.

stephane@skysql.com, returning the last generated uuid value was not part of this issue. And DEFAULT UUID() does not solve it either. It's a completely separate issue that does not affect whether this MDEV-6445 shall be closed or not.

Comment by VAROQUI Stephane [ 2016-07-28 ]

Sergei i'm quoting 2 sentences from this issue

  • "To make this work, we need to add a mysql_last_uuid() function and a LAST_UUID SQL function added."
  • "For distributed systems"

So may be this issue closing should be blocked by some missing additional task ?

Comment by Sergei Golubchik [ 2016-07-28 ]

let's consider this part of INSERT ... RETURNING task

Comment by VAROQUI Stephane [ 2016-07-28 ]

Great news thanks

Generated at Thu Feb 08 07:11:58 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.