SELECT COUNT(DISTINCT SPATIAL_POINTS_1.id) from SPATIAL_POINTS_1 as<br>
SPATIAL_POINTS_1 Inner join (Select geom from SPATIAL_POINTS_2 UNION SELECT<br>
geom from SPATIAL_POINTS_3) as SPATIAL_POINTS_X on<br>
ST_DWithin(SPATIAL_POINTS_1.the_geom, SPATIAL_POINTS_X.geom, 500)<br>
<br>
This UNION subquery is very slow, there are indexes for each geom. If I<br>
skip the UNION it's much faster.<br>
<br>
Is there an alternative way to do this?<br>