Re: spgist index not getting used - Mailing list pgsql-general

From Tom Lane
Subject Re: spgist index not getting used
Date
Msg-id 5459.1411615442@sss.pgh.pa.us
Whole thread Raw
In response to spgist index not getting used  (Paul Ramsey <pramsey@cleverelephant.ca>)
Responses Re: spgist index not getting used  (Paul Ramsey <pramsey@cleverelephant.ca>)
List pgsql-general
Paul Ramsey <pramsey@cleverelephant.ca> writes:
> My C implementation is here https://github.com/pramsey/postgis/blob/spgist/postgis/gserialized_spgist_2d.c
> My SQL binding calls are here https://github.com/pramsey/postgis/blob/spgist/postgis/gserialized_spgist_2d.sql

> Thanks to help from Andres Freund, I can now build an index based on my extension. However, when I run a query using
theoperator(s) I have defined, the query never uses my index, it always sequence scans. 

> explain analyze select * from somepoints where '(5898.82450178266,7990.24286679924)'::point = pt;

(I assume that's a typo and you meant "... &=& pt")

As stated, this WHERE clause cannot be used with the index: indexable
clauses in PG are always of the form "indexed_column operator something",
and you've written it the other way round.  I gather that you think the
operator is commutative; but since you didn't declare that, the planner
doesn't know it can flip the clause around.  Try adding "commutator = &=&"
to the declaration of the "point &=& point" operator.

            regards, tom lane


pgsql-general by date:

Previous
From: Paul Ramsey
Date:
Subject: Re: spgist index not getting used
Next
From: Paul Ramsey
Date:
Subject: Re: spgist index not getting used