<div dir="ltr"><span style="font-size:12.8000001907349px">I appreciate the quick responses. Here's the EXPLAIN for the following query:</span><div><br style="font-size:12.8000001907349px"><div style="font-size:12.8000001907349px">EXPLAIN</div><div style="font-size:12.8000001907349px">SELECT DISTINCT</div><div style="font-size:12.8000001907349px"><span style="white-space:pre-wrap">     </span>parcel.apn</div><div style="font-size:12.8000001907349px">FROM </div><div style="font-size:12.8000001907349px"><span style="white-space:pre-wrap">    </span><span class="">gis</span>.parcels as parcel, </div><div style="font-size:12.8000001907349px"><span style="white-space:pre-wrap">      </span><span class="">gis</span>.layers as layer </div><div style="font-size:12.8000001907349px">WHERE </div><div style="font-size:12.8000001907349px"><span style="white-space:pre-wrap">    </span><a href="http://layer.id/" target="_blank">layer.id</a> = 339 AND </div><div style="font-size:12.8000001907349px"><span style="white-space:pre-wrap">      </span>ST_Intersects(layer.geom_4326, parcel.geom_4326);</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Output:</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px"><div>"HashAggregate  (cost=543.84..805.23 rows=26139 width=11)"</div><div>"  Group Key: parcel.apn"</div><div>"  ->  Nested Loop  (cost=5.40..478.49 rows=26139 width=11)"</div><div>"        ->  Index Scan using layers_pkey on layers layer  (cost=0.27..8.29 rows=1 width=56409)"</div><div>"              Index Cond: (id = 339)"</div><div>"        ->  Bitmap Heap Scan on parcels parcel  (cost=5.13..469.83 rows=37 width=1018)"</div><div>"              Recheck Cond: (layer.geom_4326 && geom_4326)"</div><div>"              Filter: _st_intersects(layer.geom_4326, geom_4326)"</div><div>"              ->  Bitmap Index Scan on parcels_geom_4326  (cost=0.00..5.12 rows=111 width=0)"</div><div>"                    Index Cond: (layer.geom_4326 && geom_4326)"</div></div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px"><br></div><span style="font-size:12.8000001907349px">@Steve.Toutant, I tried your approach, but I'm still getting really slow queries(minutes). Any other ideas?</span><br></div><div><span style="font-size:12.8000001907349px"><br></span></div><div><span style="font-size:12.8000001907349px">Alexander Rolek</span></div></div>