Using PostGIS 2.0.0 I need to filter the results of a function, which returns many POINTs, to find the ones that lie within an elliptical area (like a great circle line with a buffer around it) defined by two points and a distance (all parameters passed into the query).
A filter using ST_Distance does the trick, but I wonder if there's any way to speed it up?
Simplified query:
SELECT candidate_point
FROM my_function(some, params)
WHERE
ST_Distance(candidate_point, 'SRID=4326;POINT(1 2)'::geography) +
ST_Distance(candidate_point, 'SRID=4326;POINT(3 4)'::geography) <= 60000
I tried using ST_DWithin as an additional filter, but that slows it down tenfold! Because candidate_point comes from a function, not a table, there is no index to use.