Re: How to implement a SP-GiST index as a extension module?

From: Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>
To: Connor Wolf <connorw(at)imaginaryindustries(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to implement a SP-GiST index as a extension module?
Date: 2017-11-03 22:12:43
Message-ID: CAPpHfduoHUC7dWtOkpngUqf8H-tV6xeg29zxQ8WbQ3_3Ydw-Vw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 3, 2017 at 12:37 PM, Connor Wolf <
connorw(at)imaginaryindustries(dot)com> wrote:

> EDIT: That's actually exactly how the example I'm working off of works.
> DERP. The SQL is
>
> CREATE TYPE vptree_area AS
> (
> center _int4,
> distance float8
> );
>
> CREATE OR REPLACE FUNCTION vptree_area_match(_int4, vptree_area) RETURNS
> boolean AS
> 'MODULE_PATHNAME','vptree_area_match'
> LANGUAGE C IMMUTABLE STRICT;
>
> CREATE OPERATOR <@ (
> LEFTARG = _int4,
> RIGHTARG = vptree_area,
> PROCEDURE = vptree_area_match,
> RESTRICT = contsel,
> JOIN = contjoinsel);
>
> so I just need to understand how to parse out the custom type in my index
> operator.
>

You can see the implementation of vptree_area_match function located in
vptree.c. It just calls GetAttributeByNum() function.

There is also alternative approach for that implemented in pg_trgm contrib
module. It has "text % text" operator which checks if two strings are
similar enough. The similarity threshold is defined by
pg_trgm.similarity_threshold GUC. Thus, you can also define GUC with
threshold distance value. However, it would place some limitations. For
instance, you wouldn't be able to use different distance threshold in the
same query.

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nikita Glukhov 2017-11-03 22:52:53 Re: SQL/JSON in PostgreSQL
Previous Message Alexander Korotkov 2017-11-03 22:04:22 Re: WIP: long transactions on hot standby feedback replica / proof of concept