Just a thought (from a novice postgis user) - are there spatial indexes on both tables?<br>I've forgotten to create these a couple of times and the time difference is enormous.<br><br>-David<br><br><div class="gmail_quote">
On Wed, Feb 29, 2012 at 6:15 PM, Paul Ramsey <span dir="ltr"><<a href="mailto:pramsey@opengeo.org">pramsey@opengeo.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Without a query plan (explain ... ) there's not much people can do but<br>
scratch their chins sagely.<br>
<span class="HOEnZb"><font color="#888888"><br>
P.<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Wed, Feb 29, 2012 at 3:11 PM, Jorge Gil <<a href="mailto:j.a.lopesgil@tudelft.nl">j.a.lopesgil@tudelft.nl</a>> wrote:<br>
> Hi everyone,<br>
><br>
> I've been trying to do a spatial join for a couple of days in different ways<br>
> and it never seems to finish. I've done something identical before in a much<br>
> larger set of the same data and it worked after a few hours.<br>
><br>
> I have a polygons (buildings) table with 150,000 records and a points (land<br>
> use) table with 170,000 records. I want to calculate how many points are<br>
> within each building and add that total to the column 'units' in the<br>
> buildings table. The query I run is this:<br>
><br>
> UPDATE buildings as aa SET units=bb.count FROM (SELECT cc.gid , count(*)<br>
> from buildings as cc, landuse as dd<br>
> where ST_Within(dd.the_geom, cc.the_geom) group by cc.gid) as bb WHERE<br>
> aa.gid=bb.gid;<br>
><br>
> I also try to create a separate table with the results of the join before<br>
> doing the update, but the first step also fails.<br>
><br>
> Am I doing something wrong? Is there a simple trick that makes this more<br>
> efficient?<br>
><br>
> Thank you,<br>
> Jorge<br>
><br>
> --<br>
> Jorge Gil<br>
> PhD Candidate<br>
><br>
> TU Delft / Faculty of Architecture<br>
> Department of Urbanism<br>
> Chair of Spatial Planning and Strategy<br>
><br>
> Julianalaan 134<br>
> 2628 BL Delft<br>
> P.O. Box 5043<br>
> 2600 GA Delft<br>
> The Netherlands<br>
><br>
> <a href="http://www.tudelft.nl" target="_blank">www.tudelft.nl</a><br>
><br>
> _______________________________________________<br>
> postgis-users mailing list<br>
> <a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
> <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br>