Thread: Varlena Type Creation

Varlena Type Creation

From
Dimitri Fontaine
Date:
Hi,

I'm working on a GiST opclass to support prefix searching as presented here:
http://pgsql.tapoueh.org/site/html/prefix/index.htmlhttp://prefix.projects.postgresql.org/README.html
http://cvs.pgfoundry.org/cgi-bin/cvsweb.cgi/prefix/prefix/

In order to have a much more efficient index, I received the advice to
implement a prefix range datatype then base the picksplit() and union()
implementation on top of it.

So... where do I start to create a varlena datatype which has to store the 3
following values: text prefix, char start, char end.

It's not clear for me whether this is what I need to provide:

typedef struct
{   int32    vl_len_;   char    start;   char    end;   text        prefix;
} prefix_range;

In particular, I've been taught a varlena definition can not contain pointers,
and I've no idea how to embed a text into another varlena...

Regards,
--
dim

Re: Varlena Type Creation

From
Martijn van Oosterhout
Date:
On Tue, Feb 26, 2008 at 06:19:48PM +0100, Dimitri Fontaine wrote:
> So... where do I start to create a varlena datatype which has to store the 3
> following values: text prefix, char start, char end.
>
> It's not clear for me whether this is what I need to provide:
>
> typedef struct

I see no-one responded to this: a varlena has no fixed header size, so
you can't fit it in a structure anyway. Once you're passed a pointer
you use the LEN/PTR macros to extract what you want.

Not sure what the chars are for, but perhaps it would be easiest to
treat it as a single text object with the two leading characters
signifying something?

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Those who make peaceful revolution impossible will make violent revolution inevitable.
>  -- John F Kennedy

Re: Varlena Type Creation

From
Dimitri Fontaine
Date:
Le mercredi 27 février 2008, Martijn van Oosterhout a écrit :
> I see no-one responded to this: a varlena has no fixed header size, so
> you can't fit it in a structure anyway. Once you're passed a pointer
> you use the LEN/PTR macros to extract what you want.

Once the type exists and the code gets some varlena kind type of objects to
play with, I think I'll use the same macros as for text usage... My problem
is more how to define a new "composite varlena", that is a new varlena type
composed of several base type...
I'm not sure I'm using a good vocabulary, please forgive me if it's all
unclear...

> Not sure what the chars are for

Maybe the input syntax would help getting what the chars are for.
To say a prefix range begins with '012' and any entry between '3' and '6',
you'd write e.g. '012[3-6]'::prefix_range. The chars are respectively '3'
and '6' and the greatest prefix of the prefix range is '012' here.

Here, '012[3-6]' @> '01234' is true but '012[3-6]' @> '0122' is false.

> , but perhaps it would be easiest to
> treat it as a single text object with the two leading characters
> signifying something?

I like your idea of using a single text datum for this and "encode" into it
the information I need: it makes it all simple for me to start working. But
still does not answer the question... not that the answer is needed any
more...

Thanks,
--
dim