UUID datatype GiST index support - Mailing list pgsql-hackers

From Misa Simic
Subject UUID datatype GiST index support
Date
Msg-id CAH3i69njJ9AX1fzHwt6uoUzCMBqnaDBwhmAPhRQzzLWifb2WOA@mail.gmail.com
Whole thread Raw
Responses Re: UUID datatype GiST index support
List pgsql-hackers
Hi,

Hopefully someone can help me and point me in right direction :)

I have been looking for GiST support extension for UUID datatype... since I could not find it... I wanted to write it myself.

I need it more for EXCLUSION constraint - than to use GIST index just on UUID column...

i.e:

CREATE TABLE test_exclude
(
id serial NOT NULL,
guid uuid NOT NULL,
valid_period period NOT NULL,
CONSTRAINT "test_excludepk" PRIMARY KEY (id),
EXCLUDE USING gist (guid WITH =, valid_period WITH &&) --for the same guid, period must not overlap...
)

Has taken a look on btree_gist contrib source code... there are Gist support functions for many datatypes, so I wanted to  take the same "pattern" and make it...

however, problem happend in first line of code :) (tough I am comming from totally different world - .Net)

pattern is:

typedef struct
{
      ADTdataType lower;
      ADTdataType upper;
} datatypeKEY;

i.e. for Date:

typedef struct
{
      DateADT lower;
      DateADT upper;
} dateKEY;


So I guessed for uuid would be:

typedef struct
{
      pg_uuid_t lower;
      pg_uuid_t upper;
} uuidKEY;

because of in pg uuid.h says:
 *        In C, we use the name pg_uuid_t,
 *  to avoid conflicts with any uuid_t type that might be defined by the system headers...

and there is:

/* opaque struct; defined in uuid.c */
typedef struct pg_uuid_t pg_uuid_t;


But compiler shows error: Field lower (and upper) has incopmplete datatype....

Succeded to avoid error with adding:

struct pg_uuid_t
{
  unsigned char data[UUID_LEN];
}

but then getting errors in "compare" functions:

i.e.

static int
m4_uuidkey_cmp(const void *a, const void *b)
{
uuidKEY    *ia = (uuidKEY *) (((Usrt *) a)->t);
uuidKEY    *ib = (uuidKEY *) (((Usrt *) b)->t);
int res;

res = DatumGetInt32(DirectFunctionCall2(uuid_cmp, UUIDPGetDatum(ia->upper), UUIDPGetDatum(ia->upper)));
if (res == 0)
return DatumGetInt32(DirectFunctionCall2(uuid_cmp, UUIDPGetDatum(ia->upper), UUIDPGetDatum(ib->upper)));

return res;
}


Getting error: aggregate error used where an integer was expected!

It would be a lot appreciated if anyone could help me and suggest the best way to make Gist support for UUID datatype...

Many thanks,

Misa





pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: WIP: Fast GiST index build
Next
From: Alexander Korotkov
Date:
Subject: Re: UUID datatype GiST index support