Re: Fix for typo in UUIDv7 timestamp extraction - Mailing list pgsql-hackers

From Andrey Borodin
Subject Re: Fix for typo in UUIDv7 timestamp extraction
Date
Msg-id 14A13066-25E8-4916-A1A3-8282D53F2B1E@yandex-team.ru
Whole thread Raw
In response to Fix for typo in UUIDv7 timestamp extraction  (Erik Nordström <erik@tigerdata.com>)
Responses Re: Fix for typo in UUIDv7 timestamp extraction
List pgsql-hackers
Hi Erik!

> On 13 Aug 2025, at 11:05, Erik Nordström <erik@tigerdata.com> wrote:
>
> I think I found a small typo in the function that extracts a timestamp from a UUIDv7 (uuid_extract_timestamp). Unless
Iam mistaken, the constant US_PER_MS should be used instead of NS_PER_US when converting milliseconds to microseconds.
Fortunately,these constants are the same so the calculation is still correct. 

Wow, that's a very good level of proofreading! Yes, you are correct, it's must be US_PER_MS.

>
> Anyway, attaching a patch to fix this typo.

LGTM.


>
> On a related note, I am wondering why this function doesn't extract and use the sub-millisecond information in the
rand_abits? These bits are added when generating the UUID, but they don't seem to be extracted. Hopefully somebody
couldshed some light on this and whether it would be a worthwhile addition. 

UUID might be formed by any external system, rand_a bits are not guaranteed to be non-random. Well, in some sense,
readingtime is reading random number, but anyway, we don't know for sure how those bits are used. And even in Postgres
usageof sub-millisecond fractions depends on OS. 

I think we can have a function in an extensions, that does pretend that UUID was generated by known algorithm. Or even
SQLfunction to extract microseconds. 

Thanks!


Best regards, Andrey Borodin.


pgsql-hackers by date:

Previous
From: Shlok Kyal
Date:
Subject: Re: Skipping schema changes in publication
Next
From: Shinya Kato
Date:
Subject: Re: Improve tab completion for various SET/RESET forms