MySQL 中的空间索引 - 错误 - 无法从您发送到 GEOMETRY 字段的数据中获取几何对象

我对整个空间索引"这件事很陌生,但它似乎是基于纬度/经度进行过滤的最佳解决方案.所以我在表中添加了一列:

I am new to the whole 'spatial index' thing, but it seems to be the best solution for filtering based on latitude/longitude. So I added a column to my table:

所以我创建了一个 geometry 字段:

So I created a geometry field:

  ALTER TABLE `addresses` ADD `point` POINT NOT NULL 

然后我尝试添加一个索引:

And then I tried to add an index:

  ALTER TABLE `addresses` ADD SPATIAL INDEX ( `point` ) 

但我得到一个错误:

  #1416 - Cannot get geometry object from data you send to the GEOMETRY field

我在这里做错了什么?

推荐答案

好的,我找到了解决方案:如果某些列字段不包含数据,则无法创建空间索引.运行后

OK I found the solution: Can't create a spatial index if some of the column fields contain no data. After running

  UPDATE `addresses` SET `point` = POINT( lng, lat )

一切正常.

相关文章