Re: Distance calculation - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Distance calculation
Date
Msg-id 20060117180913.GA11539@winnie.fuhr.org
Whole thread Raw
In response to Distance calculation  (<sunithab@travelpost.com>)
List pgsql-general
On Tue, Jan 17, 2006 at 10:00:22AM -0800, sunithab@travelpost.com wrote:
> I have a latiude and longitude for a city and latitude, longitude foreach
> hotel in hotels table.
>
> I have to  reitreive 20 hotels nearby to that city in 25 miles. The below
> is the query I am using to check the distance. But the query is slow
> because of distance calulation on fly and order by distance.

You appear to be using PostGIS but the query you posted doesn't use
any of PostGIS's indexable operators.  Have you read the "Using
PostGIS" documentation, in particular the parts that discuss creating
and using indexes on geometry columns?

http://postgis.refractions.net/docs/ch04.html

Your data looks like it has separate lat/lon columns when it should
have a geometry column with a GiST index.

If you're using PostGIS then you might want to subscribe to the
postgis-users mailing list:

http://postgis.refractions.net/mailman/listinfo/postgis-users

--
Michael Fuhr

pgsql-general by date:

Previous
From: John Sidney-Woollett
Date:
Subject: Re: Distance calculation
Next
From: "Andrus"
Date:
Subject: Change owner of all database objects