I don't think my query is optimized.
I want to sort the files (which each contain 1 lon and 1 lat) which are at a certain distance from a point and display the calculation of the distance between a file and the given point.
SELECT *, ST_DistanceSphere( st_point(lon, lat) , st_point(49.9, 6.7)) as result from data
where
ST_DistanceSphere( st_point(lon, lat) , st_point(49.9 ,6.7)) < 10000
so I want to retrieve the list of points which are at a distance less than 10,000 meters AND that the result column contains the calculated distance. it takes more than 1 second to return the result.
After either it is not optimized, or in postgis there is another way to get the answer faster ...
Could you please help me optimize this query?
my table:
drop table if exists data cascade;
CREATE TABLE data(
idSERIAL PRIMARY KEY,
lon float,
lat float,
);
thank you