Re: Indexing a field of type point

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Cottingham <david(dot)cottingham(at)cl(dot)cam(dot)ac(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Indexing a field of type point
Date: 2007-08-09 17:33:27
Message-ID: 17550.1186680807@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

David Cottingham <david(dot)cottingham(at)cl(dot)cam(dot)ac(dot)uk> writes:
> I have a table containing a field named location, of type point, i.e. a
> position in two dimensions. The table has several million records in, and I
> need to extract those records whose location value is contained within a
> certain bounding box.

Given the standard opclasses, your best bet is to convert the point into
a zero-volume box or circle, eg

create index i on t using gist (circle(pointcol,0))

and then express queries as "circle(pointcol,0) overlaps target-box".

PostGIS might have something more nicely adapted ...

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Joseph Krogh 2007-08-09 18:18:43 PG won't use index on ORDER BY <expression>
Previous Message David Cottingham 2007-08-09 14:01:34 Indexing a field of type point