【问题标题】:MySQL 5.7 cannot get spatial index to be usedMySQL 5.7 无法获取要使用的空间索引
【发布时间】:2021-08-03 06:40:28
【问题描述】:
CREATE TABLE zip_polygons_new(
    zipcode MEDIUMINT(5) UNSIGNED NOT NULL,
    zip_polygon MULTIPOLYGON NOT NULL,
    spatial index (zip_polygon)
);

EXPLAIN 
SELECT zipcode
FROM zip_polygons_new zp
WHERE ST_CONTAINS(zp.zip_polygon, ST_GEOMFROMTEXT('POINT(-99.24012 19.53285)'));

我总是得到:

id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE zp ALL 26376 100.0 Using where

我试过了:

  • InnoDB 和 MyIsam。
  • 几个空间函数(例如 MBRCONTAINS、ST_CONTAINS)。
  • 在 WHERE 子句的 RHS 上将等于 1。

已检查: MySQL 文档 Mysql Spatial index unused Why Spatial index not used by MySQL?

我缺少什么才能使用索引?

【问题讨论】:

    标签: mysql sql indexing spatial


    【解决方案1】:

    事实证明我没有意识到我已经运行了 mysql@8,当切换回 mysql@5.7 时,现在使用了索引。

    所以问题出在 mysql@8 上,因为我的问题与 mysql@5.7 有关,我认为它是自我回答的。可能问题在于 mysql@8 需要一个显式的 SRID 来使用空间索引,而 mysql@5.7 没有。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-30
      • 2011-12-08
      • 1970-01-01
      • 2018-04-11
      • 1970-01-01
      • 2022-01-06
      • 2020-09-29
      相关资源
      最近更新 更多