<font size=3>Alexander,</font>
<br><font size=3>Using explain, make sure the where clause is used before
the intersects function. </font>
<br><font size=3>Maybe this query will help.</font>
<br><font size=3>SELECT DISTINCT parcel.apn</font>
<br><font size=3>FROM </font>
<br><font size=3>gis.parcels as parcel</font>
<br><font size=3>JOIN (select geom_4326 from gis.layers where </font><a href=http://layer.id/><font size=3 color=blue><u>layer.id</u></font></a><font size=3>
= 339) as layer ON ST_Intersects(layer.geom_4326, parcel.geom_4326); </font>
<br>
<br><font size=2 face="sans-serif">It might help to have an index on layer.id...maybe
not...you coulkd try</font>
<br>
<p>
<br>
<br>
<br>
<table width=100% style="border-collapse:collapse;">
<tr valign=top height=8>
<td width=40% style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;"><font size=1 face="sans-serif"><b>"Alexander
W. Rolek" <a.rolek@gmail.com>@lists.osgeo.org</b> </font>
<br><font size=1 face="sans-serif">Envoyé par : postgis-users-bounces@lists.osgeo.org</font>
<p><font size=1 face="sans-serif">2015-05-26 16:01</font>
<table width=169 style="border-collapse:collapse;">
<tr valign=top height=8>
<td width=167 bgcolor=white style="border-style:solid solid solid solid;border-color:#000000;border-width:1px 1px 1px 1px;padding:0px 0px;">
<div align=center><font size=1 face="sans-serif">Veuillez répondre à<br>
PostGIS Users Discussion <postgis-users@lists.osgeo.org></font></div></table>
<br>
<td width=59% style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;">
<table width=100% style="border-collapse:collapse;">
<tr valign=top height=21>
<td width=57 style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;">
<div align=right><font size=1 face="sans-serif">A</font></div>
<td style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;"><font size=1 face="sans-serif">PostGIS
Users Discussion <postgis-users@lists.osgeo.org></font>
<tr valign=top height=21>
<td width=57 style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;">
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;">
<tr valign=top height=21>
<td width=57 style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;">
<div align=right><font size=1 face="sans-serif">Objet</font></div>
<td style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;"><font size=1 face="sans-serif">[postgis-users]
Slow ST_Intersects and Materialized Views</font></table>
<br>
<table width=393 style="border-collapse:collapse;">
<tr valign=top height=8>
<td width=57 style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;">
<td width=336 style="border-style:none none none none;border-color:#000000;border-width:0px 0px 0px 0px;padding:0px 0px;"></table>
<br></table>
<br>
<br>
<br>
<br>
<br><font size=3>I have two tables both which have a gemo_4326 columns
with a GIST index.</font>
<ul>
<li><font size=3>gis.parcels (approximately 1 million records)</font>
<li><font size=3>gis.layers (approximately 1 thousand records)</font></ul><font size=3>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.</font>
<br>
<br><font size=3>Here's my query:</font>
<br>
<br><font size=3>SELECT DISTINCT</font>
<br><font size=3>parcel.apn</font>
<br><font size=3>FROM </font>
<br><font size=3>gis.parcels as parcel, </font>
<br><font size=3>gis.layers as layer </font>
<br><font size=3>WHERE </font>
<br><a href=http://layer.id/><font size=3 color=blue><u>layer.id</u></font></a><font size=3>
= 339 AND </font>
<br><font size=3>ST_Intersects(layer.geom_4326, parcel.geom_4326);</font>
<br>
<br><font size=3>Two questions:</font>
<ul>
<li><font size=3>How can I improve performance on the ST_Intersects from
gis.layers -> gis.parcels?</font>
<li><font size=3>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?</font></ul>
<br><font size=3>-- </font>
<br><font size=3>Alexander W. Rolek<br>
</font><tt><font size=2>_______________________________________________<br>
postgis-users mailing list<br>
postgis-users@lists.osgeo.org<br>
</font></tt><a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users"><tt><font size=2>http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</font></tt></a>
<br>
<br>
<br>