我有3列公司的地址表:company_id,lat,lon.
我需要与每家公司保持最近的距离.我为PostgreSQL 使用cube和earthdistance扩展.
查询工作正常但很慢:
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;
Run Code Online (Sandbox Code Playgroud)
GIST索引如:
CREATE INDEX i_name on companies USING gist(ll_to_earth(lat, lon));
Run Code Online (Sandbox Code Playgroud)
不使用.
我该如何解决这个问题?谢谢.