Hi Daniel! > On 16 Dec 2024, at 19:08, Daniel Verite <dan...@manitou-mail.org> wrote: > > The timestamps are now just a sequence incrementing by 1 > on each call, independently of the server's clock and > the actual time span between calls. It has become a counter > and will remain so until the backend terminates.
This is exactly what RFC suggest us to do. It’s a feature, not a bug. > > It does not have to be that way. In get_real_time_ns_ascending(), > it could switch immediately to the new time: > > diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c > index 2e32592f57..8df194daea 100644 > --- a/src/backend/utils/adt/uuid.c > +++ b/src/backend/utils/adt/uuid.c > @@ -505,8 +505,11 @@ get_real_time_ns_ascending() > ns = tmp.tv_sec * NS_PER_S + tmp.tv_nsec; > #endif > > - /* Guarantee the minimal step advancement of the timestamp */ > - if (previous_ns + SUBMS_MINIMAL_STEP_NS >= ns) > + /* > + * Guarantee the minimal step advancement of the timestamp, > + * unless the clock has moved backward. > + */ > + if (previous_ns + SUBMS_MINIMAL_STEP_NS >= ns && previous_ns <= ns) > ns = previous_ns + SUBMS_MINIMAL_STEP_NS; > previous_ns = ns; We have that previous_ns to protect us from clocks moving backwards. And you suggest us to disable this protection. To achieve this we would rather delete previous_ns at all. It was there not to guarantee minimal step, but to ensure clocks always move forward only. > >> Also PFA a prototype of making uuidv7() ordered across all backends via >> keeping previous_ns in shared memory. IMO it's overcomplicating and RFC >> does not require such guarantees > > It does not have to be in core, but an extension might want to provide > a generator that guarantees monotonicity across backends. AFAIK extension pg_uuidv7 does not have this protection right now. But Florian might add it in future. Best regards, Andrey Borodin.