Distance calculation - Mailing list pgsql-general

From
Subject Distance calculation
Date
Msg-id 001101c61b8f$e3211ff0$1301a8c0@sf.vagabond.com
Whole thread Raw
Responses Re: Distance calculation  (John Sidney-Woollett <johnsw@wardbrook.com>)
Re: Distance calculation  (Michael Fuhr <mike@fuhr.org>)
Re: Distance calculation  (Tino Wildenhain <tino@wildenhain.de>)
List pgsql-general
Hi

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.

Can anybody help me how can I improve performance by refining lat and long
data.
v_point is the city lat and long.(point(citylong citylat))

  SELECT pr.property_id
   , pr.property_type As property_type_id
    , pr.property_name
     ,round (DISTANCE( v_point:: geometry,
                   POINTFromText('Point(' ||pr.long ||' ' ||
pr.lat||')')::geometry) *69.055) as CityToHotelDistance
        FROM property.property pr
         INNER JOIN place p ON (pr.place_id = p.place_id)
        INNER JOIN placedetail pd ON (p.place_id = pd.place_id)
        LEFT OUTER JOIN property.vw_property_price vwp ON (vwp.property_id =
pr.property_id)
        WHERE DISTANCE( v_point :: geometry,
                   POINTFromText('Point(' ||pr.long ||' ' ||
pr.lat||')')::geometry) < .4  AND pr.place_id != p_place_id
                   AND (pr.status_type_id is null OR pr.status_type_id = 0)
                   ORDER BY DISTANCE( v_point :: geometry,
                   POINTFromText('Point(' ||pr.long ||' ' ||
pr.lat||')')::geometry)
                   offset 0 LIMIT 20;


pgsql-general by date:

Previous
From: David Fetter
Date:
Subject: Re: PostgreSQL Top 10 Wishlist
Next
From: "Qingqing Zhou"
Date:
Subject: Re: Huge number of disk writes after migration to 8.1