PostGIS offers a list of operators implementing spatial relations. Some of them have a direct function equivalent, for example <->
and ST_Distance
.
EXPLAIN
SELECT
st_distance(st_setsrid(st_makepoint(0, 0), 4326),
st_setsrid(st_makepoint(10, 10), 4326))
and
EXPLAIN
SELECT
st_setsrid(st_makepoint (0, 0), 4326) <->
st_setsrid(st_makepoint (10, 10), 4326)
yield the exact same query plan. Are there any scenarios in which one method is preferable to the other?
For PostgreSQL below 9.5 only gives centroid distance of bounding boxes and for PostgreSQL 9.5+, does true KNN distance search giving true distance between geometries, and distance sphere for geographies.