运行 在 MySQL 中重复复杂空间查询时性能下降

Slow performance when running repeated complex spatial query in MySQL

我正在按距离搜索圆 select。我有一个纬度和经度点,我想搜索数据库中是否有我周围的一些点。是的,它一定是一个圆圈!

我在查询中使用这个子句(我只是 google 它,我不会做数学):

((6373 * acos (cos ( radians( 48.568962 ) ) * cos( radians( X(coords) ) ) * cos( radians( Y(coords) ) - radians( 6.821352 ) ) + sin ( radians( 48.568962 ) ) * sin( radians( X(coords) ) )))  <='0.2')

0.2 = 200 米

  1. 我正在使用 POINT 数据类型
  2. 是的,我有 SPATIAL 索引
  3. 是的,我正在尝试使用 "spatial" 函数,但它没有返回圆,而是返回一些 OVAL,我需要 PRECISE 圆

这个 "circle" 子句对所有 table 来说需要非常非常非常长的时间。当我使用 SPATIAL foos 的 OVAL 方法时。可能需要 0.1 秒,这太棒了!但我需要圆,这需要 17 秒,大声笑。

你能帮帮我吗?非常感谢你们!

编辑:空间函数的意思是这样的:

WHERE ST_Contains(ST_Buffer(
      ST_GeomFromText('POINT(12.3456 34.5678)'), (0.00001*1000)) , coords) <= 1 /* 1 km */

编辑 2(table 结构。):

我希望从这个 table 中得到 10 行,当然我在 wz_uuid

上有索引
select a....., b.... from table_1 a left join table_2 b on a.wz_uuid=b.wz_uuid

而且这不仅仅是 2 tables,我有 11 tables *2 这样的。 (每周数据库备份)。首先 tables (_1) 有 0-4000 行,2-11 有 300k+ 行。

所有索引都是相关的,还有数据类型和编码。

wz_uuid & id - unique, btree index
others - btree indexes
coords - spatial index

从 XX 秒到 100 毫秒的完美解决方案,这就是我想要的:-)

Use MySQL spatial extensions to select points inside circle