Re: UUID v7

From: Jelte Fennema <postgres(at)jeltef(dot)nl>
To: Nick Babadzhanian <pgnickb(at)gmail(dot)com>
Cc: "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>, Mat Arye <mat(at)timescaledb(dot)com>, Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Daniel Gustafsson <daniel(at)yesql(dot)se>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Nikolay Samokhvalov <samokhvalov(at)gmail(dot)com>, "Kyzer Davis (kydavis)" <kydavis(at)cisco(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, Andrey Borodin <amborodin86(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, "brad(at)peabody(dot)io" <brad(at)peabody(dot)io>, "wolakk(at)gmail(dot)com" <wolakk(at)gmail(dot)com>, sergeyprokhorenko(at)yahoo(dot)com(dot)au
Subject: Re: UUID v7
Date: 2023-10-09 18:11:07
Message-ID: CAGECzQQ3k66bnseNzTrvakjK7HRaL1k0LT+FEt0yjjVeZb8gjw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, 9 Oct 2023 at 18:46, Nick Babadzhanian <pgnickb(at)gmail(dot)com> wrote:
>
> On Thu, 31 Aug 2023 at 23:10, Andrey M. Borodin <x4mmm(at)yandex-team(dot)ru> wrote:
> > Well, as far as I know, RFC discourages extracting timestamps from UUIDs. But we still can have such functions...maybe as an extension?
>
> Do you know of any reason for that?

No reasons are given but the RFC states this:

> UUIDs SHOULD be treated as opaque values and implementations SHOULD NOT examine the bits in a UUID to whatever extent is possible. However, where necessary, inspectors should refer to Section 4 for more information on determining UUID version and variant.

> > However, so far I haven't figured out how to implement optional arguments for catalog functions. I'd appreciate any pointers here.
>
> I'd argue that the time argument shouldn't be optional. Asking the
> user to supply time would force them to think whether they want to go
> with `now()` or `clock_timestamp()` or something else.

I think using `now()` is quite prone to sequence rollover. With the
current patch inserting more than 2^18~=0.26M rows into a table with
`gen_uuid_v7()` as the default in a single transaction would already
cause sequence rollover. I think using a monotonic clock source is the
only reasonable thing to do. From the RFC:

> Implementations SHOULD use the current timestamp from a reliable source to provide values that are time-ordered and continually increasing. Care SHOULD be taken to ensure that timestamp changes from the environment or operating system are handled in a way that is consistent with implementation requirements. For example, if it is possible for the system clock to move backward due to either manual adjustment or corrections from a time synchronization protocol, implementations must decide how to handle such cases. (See Altering, Fuzzing, or Smearing bullet below.)

In response to

  • Re: UUID v7 at 2023-10-09 16:46:17 from Nick Babadzhanian

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Brad Peabody 2023-10-09 18:42:20 Re: UUID v7
Previous Message Tom Lane 2023-10-09 17:38:01 Re: Making aggregate deserialization (and WAL receive) functions slightly faster