我有一张桌子叫place:
id | name | coordinates (longitude, latitude)
1 | London | -0.12574, 51.50853
2 | Manchester | -2.25, 53.41667
3 | Glasgow | -4.25, 55.86667
Run Code Online (Sandbox Code Playgroud)
该coordinates列是点数据类型。我place使用以下方法将点插入表中:
st_geomfromtext('point($longitude $latitude)', 4326)
Run Code Online (Sandbox Code Playgroud)
请注意,我使用了 SRID。
给定任何坐标,我想找到离它最近的地方(按升序排列)。我目前提出的解决方案(通过阅读 MySQL 文档)如下所示:
select
*,
st_distance_sphere(`place`.`coordinates`, st_geomfromtext('Point($longitude $latitude)', 4326)) as distance
from place
order by distance asc;
Run Code Online (Sandbox Code Playgroud)
在查看了此处和其他地方的无数类似问题后,很明显这是一种鲜为人知(和较新的方式)的做事方式,因此没有太多内容,因此我要寻求一些澄清。
我的问题是:
coordinates列上的空间索引吗?编辑,这里是这些答案:
explain select ...; 返回:
id | select_type | table | partitions | …Run Code Online (Sandbox Code Playgroud)