<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">Hey,<br></div><div class="gmail_default" style="font-family:monospace,monospace">the type of info you should consider to give for a meaningfull answer :<br><a href="https://wiki.postgresql.org/wiki/Slow_Query_Questions">https://wiki.postgresql.org/wiki/Slow_Query_Questions</a><br><br></div><div class="gmail_default" style="font-family:monospace,monospace">The slowness could come from many things.<br><br></div><div class="gmail_default" style="font-family:monospace,monospace">For instance <br><div><span style="white-space:pre-wrap">     </span><a href="http://layer.id" target="_blank">layer.id</a> = 339 AND </div><div><span style="white-space:pre-wrap">       </span>ST_Intersects(layer.geom_4326, parcel.geom_4326);<br></div><div>You use 2 conditions, postgres might choose to use first the bad one.<br><br></div><div>You could try to manually force postgres to use first the spatial condition for instance.<br><br></div><div>I'm guessing you have an index on <a href="http://layer.id">layer.id</a> anyway.<br><br><br></div><div>Your query feels akward<br><br><br></div></div><div class="gmail_default" style="font-family:monospace,monospace"><br><br><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-05-26 22:01 GMT+02:00 Alexander W. Rolek <span dir="ltr"><<a href="mailto:a.rolek@gmail.com" target="_blank">a.rolek@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I have two tables both which have a gemo_4326 columns with a GIST index.<div><ul><li>gis.parcels (approximately 1 million records)<br></li><li>gis.layers (approximately 1 thousand records)<br></li></ul><div>The gis.layers table has large multipolygons that can include thousands of gis.parcel intersects. When I run ST_Intersects from a gis.parcel row to gis.layers the query is pretty quick (sub 100 ms). When I run an ST_Intersects on a large multipolygon from gis.layers to gis.parcels to find which parcels intersect with the gis.layer, the queries can take upwards of 10 minutes.<br></div></div><div><br></div><div>Here's my query:</div><div><br></div><div><div><div>SELECT DISTINCT</div><div><span style="white-space:pre-wrap">      </span>parcel.apn</div><div>FROM </div><div><span style="white-space:pre-wrap">  </span>gis.parcels as parcel, </div><div><span style="white-space:pre-wrap"> </span>gis.layers as layer </div><div>WHERE </div><div><span style="white-space:pre-wrap">      </span><a href="http://layer.id" target="_blank">layer.id</a> = 339 AND </div><div><span style="white-space:pre-wrap">       </span>ST_Intersects(layer.geom_4326, parcel.geom_4326);</div></div></div><div><br><div>Two questions:</div><div><ul><li>How can I improve performance on the ST_Intersects from gis.layers -> gis.parcels?</li><li>I'm considering caching the results in a Materialized View, but based on the current performance this would take a couple days. Is there an alternative approach for caching the results?</li></ul></div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- <br><div>Alexander W. Rolek<br><br></div>
</div></font></span></div></div>
<br>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br></blockquote></div><br></div>