Re: What's the best way to index this table for speed?

From: Steve Wormley <steve(at)wormley(dot)com>
To: Carl Lerche <carl(dot)lerche(at)gmail(dot)com>, Untitled 5 <pgsql-general(at)postgresql(dot)org>
Subject: Re: What's the best way to index this table for speed?
Date: 2007-02-01 18:51:11
Message-ID: C1E7769F.5E667%steve@wormley.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2/1/07 10:42 AM, "Carl Lerche" <carl(dot)lerche(at)gmail(dot)com> wrote:

> How can I index 2 dimensional data (latitude / longitude) with a
> status_id column too (integer) so that I can perform the following
> query as fast as possible:
>
> SELECT * FROM profiles WHERE status_id = 1 AND latitude BETWEEN
> <y_1> AND <y_2> AND longitude BETWEEN <x_1> AND <x_2>;

Depending on what your needs are, I'd look into PostGIS and make your data
points and doing bounding box queries using a GIST index either with a
partial index or indexes depending on how many status ids:

create index xyz on profiles using gist(mypoint) where status_id = 1;

Or a multicolumn index using the btree_gist contrib module:

create index xyz on profiles using gist (status_id,mypoint);

I use the first format as I only have 2 statuses, valid and not valid and it
works quite well. If PostGIS won't work for you you still can possibly use a
partial index if it works for your status_ids.

-Steve Wormley
Senior Consultant
inCode Wireless
a Verisign Company

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruno Wolff III 2007-02-01 19:19:41 Re: What's the best way to index this table for speed?
Previous Message korryd 2007-02-01 18:43:51 Re: How to allow users to log on only from my application