Re: Distance calculation

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: sunithab(at)travelpost(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Distance calculation
Date: 2006-01-17 18:09:14
Message-ID: 20060117180913.GA11539@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Jan 17, 2006 at 10:00:22AM -0800, sunithab(at)travelpost(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrus 2006-01-17 18:10:56 Change owner of all database objects
Previous Message sunithab 2006-01-17 18:00:22 Distance calculation