Hi,<div><br></div><div>I am working on a query where i want to measure the distance from a set of points, to the nearest point having a spi6 value over 0.</div><div>The priogrid includes the points and the spi6_cell identifies which points have a spi6 over 0.</div>
<div><br></div><div>My question is whether i can optimize this for better performance?</div><div>As for now it takes 66 minutes for one year. Having 53 years that would take like 58 hours to complete.</div><div>Using my St_DWithin(), does it restrict the distance measures to only points within 500 km?</div>
<div><br></div><div>My query:</div><div><div>SELECT p.gid, s.gridyear, MIN(ST_Distance(p.centroid::geography, p2.centroid::geography))/1000 AS distance</div><div>FROM priogrid p, priogrid p2, spi6_cell s</div><div>WHERE p2.gid = s.gid AND s.spi6 >= 0.5 AND s.gridyear = 1952 AND ST_DWithin(p.centroid::geography, p2.centroid::geography, 500000) </div>
<div>GROUP BY p.gid, s.gridyear</div><div>ORDER BY distance;</div></div><div><br></div><div>"POSTGIS="2.0.0SVN" GEOS="3.4.0dev-CAPI-1.8.0" PROJ="Rel. 4.7.1, 23 September 2009" GDAL="GDAL 1.9.0, released 2011/12/29" LIBXML="2.7.8" USE_STATS (procs from 2.0 r need upgrade)"</div>
<div>PostGIS Revision 8622</div><div>"PostgreSQL 9.1.1 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1, 64-bit"</div><div><br></div><div>Any help would be very appreciated.</div>
<div><br></div><div><br></div>