pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Masahiko Sawada <msawada@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add UUID version 7 generation function.
Date: Wed, 11 Dec 2024 23:54:55 +0000
Message-ID: <E1tLWXf-002GcM-A3@gemulon.postgresql.org> (raw)

Add UUID version 7 generation function.

This commit introduces the uuidv7() SQL function, which generates UUID
version 7 as specified in RFC 9652. UUIDv7 combines a Unix timestamp
in milliseconds and random bits, offering both uniqueness and
sortability.

In our implementation, the 12-bit sub-millisecond timestamp fraction
is stored immediately after the timestamp, in the space referred to as
"rand_a" in the RFC. This ensures additional monotonicity within a
millisecond. The rand_a bits also function as a counter. We select a
sub-millisecond timestamp so that it monotonically increases for
generated UUIDs within the same backend, even when the system clock
goes backward or when generating UUIDs at very high
frequency. Therefore, the monotonicity of generated UUIDs is ensured
within the same backend.

This commit also expands the uuid_extract_timestamp() function to
support UUID version 7.

Additionally, an alias uuidv4() is added for the existing
gen_random_uuid() SQL function to maintain consistency.

Bump catalog version.

Author: Andrey Borodin
Reviewed-by: Sergey Prokhorenko, Przemysław Sztoch, Nikolay Samokhvalov
Reviewed-by: Peter Eisentraut, Jelte Fennema-Nio, Aleksander Alekseev
Reviewed-by: Masahiko Sawada, Lukas Fittl, Michael Paquier, Japin Li
Reviewed-by: Marcos Pegoraro, Junwang Zhao, Stepan Neretin
Reviewed-by: Daniel Vérité
Discussion: https://postgr.es/m/CAAhFRxitJv%3DyoGnXUgeLB_O%2BM7J2BJAmb5jqAT9gZ3bij3uLDA%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/78c5e141e9c139fc2ff36a220334e4aa25e1b0eb

Modified Files
--------------
doc/src/sgml/datatype.sgml         |   2 +-
doc/src/sgml/func.sgml             |  30 +++--
src/backend/utils/adt/uuid.c       | 248 +++++++++++++++++++++++++++++++++++--
src/include/catalog/catversion.h   |   2 +-
src/include/catalog/pg_proc.dat    |  11 +-
src/test/regress/expected/uuid.out |  56 ++++++++-
src/test/regress/sql/uuid.sql      |  28 ++++-
7 files changed, 353 insertions(+), 24 deletions(-)



Message-ID: <E1tLWXf-002GcM-A3@gemulon.postgresql.org>
Permalink:  ../E1tLWXf-002GcM-A3@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1tLWXf-002GcM-A3@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: msawada@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Add UUID version 7 generation function.
  In-Reply-To: <E1tLWXf-002GcM-A3@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox