I have the following query that finds all id
inside POLYGON(({points}))
SELECT id
FROM t
WHERE ST_DWithin('POLYGON(({points}))', ST_Point(latitude, longitude), 0);
The query is slow because it doesn't use the (latitude, longitude) index and must compute the formula for every possible pair of points.
How can I change my query to force Postgres to use the (latitude, longitude)
index (I need to change the query because I cannot add some other index or create/change the table)?
I have the following index:
"index_latitude_longitude" btree (latitude, longitude)
latitude, longitude
has double precision type.
I think that Postgres will use the index if we add something like: latitude <= ... and longitude <= ...
. How can we do this?