[postgis-users] optimize query

Paul Ramsey pramsey at refractions.net
Fri Mar 9 12:09:52 PST 2007


Never buffer to return a boolean, it's a waste of CPU cycles (though 
since you are only buffering one point, it's not harmful in this case).

select
   freguesia,
   distance(geomfromtext('POINT(-9.17266 38.68783)',4326),f.geometry) as 
thedist
from
   warped_freguesias as f
WHERE
   f.geometry &&
   expand(geomfromtext('POINT(-9.17266 8.68783)',4326), 0.016)
order by thedist

limit 1;



Pedro Doria Meunier wrote:
> select freguesia, distance(geomfromtext('POINT(-9.17266 
> 38.68783)',4326),f.geometry) as thedist
> 
> from warped_freguesias as f
> 
> WHERE f.geometry && buffer(geomfromtext('POINT(-9.17266 
> 38.68783)',4326), 0.016)
> 

-- 

   Paul Ramsey
   Refractions Research
   http://www.refractions.net
   pramsey at refractions.net
   Phone: 250-383-3022
   Cell: 250-885-0632



More information about the postgis-users mailing list