Extending the KD Tree index in Postgresql 9.2.1

From: JP <jeanpaul(dot)ebejer(at)inhibox(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Extending the KD Tree index in Postgresql 9.2.1
Date: 2012-12-05 16:03:42
Message-ID: CAKwxoo6fCDVTf-N+mcKgPwXQHpoQyauoJizVrpLKyk6KOz0uFA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi there Postgressors,

I have a 15-element/dimension vector (floats) data type. I also have about
10 million of these and given a query vector I would like to search these
to find a number of nearest neighbours.

For this I intend to extend the current implementation of kd tree
in postgresql-9.2.1/src/backend/access/spgist in file spgkdtreeproc.c.
This implementation currently works on points (2D).

So till now I have implemented my user defined type in a new
contrib/folder. I can install the extension and use my datatype in a table
definition. So far, so good.

But I am having problems understanding the whole indexing mechanism. And
how I can interface with the postgres indexing. To start with, should I be
building an index from scratch or using the current GiST-based
implementation?

I copied the spgkdtreeproc.c and created my own modified version (in
the postgresql-9.2.1/src/backend/access/spgist) directory. How will
postgres know when to use my functions instead of what is currently in
place? They are named differently of course, but where is the link between
the index and my functions?

Another thing which I do not get is in

Datum
spg_kd_inner_consistent(PG_FUNCTION_ARGS)

There are multiple sk_strategy defined (e.g. RTLeftStrategyNumber,
RTRightStrategyNumber, RTSameStrategyNumber, etc). Who/where is this
strategy being set? What does this mean? Is it just browsing through the
underlying binary tree? I will have to extend this method: as I want to
implement a 15-dimensional RTContainedByStrategyNumber (rather than the
current BOX being used) - correct? Also where is the BOX parameter being
set, by which codebase?

I have read the chapters 52-54 of the postgres documentation but I am none
the wiser - if you can point me to the right documentation/tutorial I would
be eternally grateful.

Many Thanks for your newbie patience,
-
Jean-Paul Ebejer
Early Stage Researcher

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2012-12-05 16:24:49 Re: Extending the KD Tree index in Postgresql 9.2.1
Previous Message Tom Lane 2012-12-05 15:58:54 Re: CREATE RULE fails with 'ERROR: SELECT rule's target list has too many entries'