Re: Review: GiST support for UUIDs

From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Ildus Kurbangaliev <i(dot)kurbangaliev(at)postgrespro(dot)ru>, Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
Cc: Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Review: GiST support for UUIDs
Date: 2015-12-25 10:34:25
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Thank you, but I have some notices about
static float
uuid_parts_distance(pg_uuid_t *a, pg_uuid_t *b)
pg_uuid_t ua, ub;
const double mp = pow(2, -64);

uuid_cnv(a, &ua);
uuid_cnv(b, &ub);

Assert(ua.v64[0] > ub.v64[0]);
uint64 high = ua.v64[0] - ub.v64[0];
uint64 low = ua.v64[1] - ub.v64[1];
if (low > ua.v64[1])

return (float) (ldexp(high, 64) + (double) low * mp);

First, variables (high and low) should not be declared in the middle of code.
Second, assert will fail if ua.v64[0] == ub.v64[0] and
ua.v64[1] > ub.v64[1] although it's a possible and allowed case. Third, actually
you multiply high value by 2^64 anf low by 2^-64. Seems, it's needed to do only
one multiplication.

Ildus Kurbangaliev wrote:
> On Wed, 23 Dec 2015 16:36:23 -0800
> Paul Jungwirth <pj(at)illuminatedcomputing(dot)com> wrote:
>> On 12/23/2015 08:10 AM, Ildus Kurbangaliev wrote:
>>> There is a more improved version of the patch. Main idea is to
>>> present uuid as two uint64 values, and make comparisons and penalty
>>> calculation based on these values. This approach is much faster
>>> than using memcmp for uuid comparisons.
>> Thank you for picking this up! I'm sorry I was not able to work on it
>> the last few months. I'm very glad to see someone wrapping it up. I'm
>> not a reviewer, but personally it looks like a good change to me.
>> Happy holidays,
>> Paul
> Thanks! The patch was almost done and ready. I attached new version of
> the patch with compability changes.

Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Ildus Kurbangaliev 2015-12-25 11:23:40 Re: Review: GiST support for UUIDs
Previous Message Fornaroli Christophe 2015-12-25 10:19:48 Re: Patch: pg_trgm: gin index scan performance for similarity search