F
F
furyon2018-01-08 09:00:39
PostgreSQL
furyon, 2018-01-08 09:00:39

How to speed up geodata fetch query in PostgreSQL?

For example, there is a table of company addresses with 3 fields: company_id , lat , lon .
It is necessary to obtain the distances to the nearest address of each of the companies.
To work with geodata, I use the cube and earthdistance extensions .
I am running a query:

SELECT
 company_id,
 MIN(earth_distance(ll_to_earth(lat,lon), ll_to_earth(53.96,83.96))) AS distance
FROM companies
GROUP BY company_id;

The request does what it needs to, but slowly. GIST type index
CREATE INDEX i_name on companies USING gist(ll_to_earth(lat, lon));
Does not help.
Are there ways to speed up such a request?
PS
Asked a question on SO https://stackoverflow.com/questions/48146004/how-t...
The answer marked as a solution made it possible to increase the speed of the script by 3 times.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fixid, 2018-01-08
@Fixid

Use PostGIS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question