I have a table called Stores
with 10k rows which has a column location geometry(Point,4326)
.
CREATE INDEX "Stores_spatial_gix"
ON "Stores"
USING gist
(location);
Upon KNN query
explain analyze select *
from "Stores"
order by ST_distance_sphere(location,st_point(-82.373978, 29.633657)) limit 3
I get about 800ms each time. What am I doing wrong that it takes so long time?
point
column and an index gives out the same KNN query in 0.452 ms! So there is something definitely off here. Due to some library dependency I'm stuck withgeometry
and can't usepoint
. So it is possible, but needs a right approach.