Re: [HACKERS] How to implement a SP-GiST index as a extension module? - Mailing list pgsql-hackers

From Alexander Korotkov
Subject Re: [HACKERS] How to implement a SP-GiST index as a extension module?
Date
Msg-id CAPpHfduoHUC7dWtOkpngUqf8H-tV6xeg29zxQ8WbQ3_3Ydw-Vw@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] How to implement a SP-GiST index as a extension module?  (Connor Wolf <connorw@imaginaryindustries.com>)
Responses Re: [HACKERS] How to implement a SP-GiST index as a extension module?  (Connor Wolf <connorw@imaginaryindustries.com>)
List pgsql-hackers
On Fri, Nov 3, 2017 at 12:37 PM, Connor Wolf <connorw@imaginaryindustries.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
 

pgsql-hackers by date:

Previous
From: Alexander Korotkov
Date:
Subject: Re: [HACKERS] WIP: long transactions on hot standby feedback replica/ proof of concept
Next
From: Nikita Glukhov
Date:
Subject: Re: [HACKERS] SQL/JSON in PostgreSQL