Re: Review: GiST support for UUIDs - Mailing list pgsql-hackers

From Paul Jungwirth
Subject Re: Review: GiST support for UUIDs
Date
Msg-id 55F722EF.1010804@illuminatedcomputing.com
Whole thread Raw
In response to Review: GiST support for UUIDs  (Teodor Sigaev <teodor@sigaev.ru>)
Responses Re: Review: GiST support for UUIDs  (Teodor Sigaev <teodor@sigaev.ru>)
List pgsql-hackers
> 2)
>      static double
>      uuid2num(const pg_uuid_t *i)
>      {
>          return *((uint64 *)i);
>      }
>     It isn't looked as correct transformation for me. May be, it's better
>     to transform to numeric type (UUID looks like a 16-digit hexademical
> number)
>     and follow  gbt_numeric_penalty() logic (or even call directly).

Thanks for the review! A UUID is actually not stored as a string of 
hexadecimal digits. (It is normally displayed that way, but with 32 
digits, not 16.) Rather it is stored as an unstructured 128-bit value 
(which in C is 16 unsigned chars). Here is the easy-to-misread 
declaration from src/backend/utils/adt/uuid.c:

#define UUID_LEN 16
struct pg_uuid_t
{
unsigned char data[UUID_LEN];
};

I would love to just cast this to a 128-bit unsigned int. But it looks 
like Postgres doesn't always have 128-bit ints available, so my code 
takes the top half and uses that for penalty calculations. It seemed to 
me that was "good enough" for this purpose.

The only other 128-bit type I found in btree_gist was Interval. For that 
type we convert to a double using INTERVAL_TO_SEC, then call 
penalty_num. By my read that accepts a similar loss of precision.

If I'm mistaken about 128-bit integer support, let me know, and maybe we 
can do the penalty computation on the whole UUID. Or maybe I should just 
convert the uint64 to a double before calling penalty_num? I don't 
completely understand what the penalty calculation is all about, so I 
welcome suggestions here.

Thanks again,
Paul












pgsql-hackers by date:

Previous
From: Teodor Sigaev
Date:
Subject: Re: cache type info in json_agg and friends
Next
From: Andrew Dunstan
Date:
Subject: Re: cache type info in json_agg and friends