mysql8使用gis功能,建立SPATIAL KEY 空间索引,explain发现索引未生效
CREATE TABLE `geom` (
`g` geometry NOT NULL,
SPATIAL KEY `g` (`g`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO emergency_fire.geom
(g)
VALUES(ST_GeomFromText('LINESTRING(30350 15828,30350 15845)'));
INSERT INTO emergency_fire.geom
(g)
VALUES(ST_GeomFromText('LINESTRING(30350 15871,30350 15887)'));
explain SELECT ST_AsText(g) FROM geom WHERE
MBRContains(ST_GeomFromText('Polygon((30000 15000,
31000 15000,
31000 16000,
30000 16000,
30000 15000))'),g);
多次实验后发现,必须添加SRID 空间引用标识符 配置(注释),索引才能生效。
CREATE TABLE `geom` (
`g` geometry NOT NULL /*!80003 SRID 0 */,
SPATIAL KEY `g` (`g`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
MBRContains、ST_Contains 等空间计算索引都可以生效
SRID默认为0
其他常用的还有SRID 4326,映射WGS 84坐标。(latitude经度[-90,90] longitude经度[-180,180])