我们已经在amazonrds上将mysql 5.7数据库的副本迁移到mysql 8.0.11。在可能的情况下,一切都是一样的。已修改包含几何图形数据的表,因此几何图形列仅限于srid 0,并重建空间索引。两个数据库上的执行计划是相同的,表明查询使用的是空间索引。
在MySQL5.7上,以下查询需要0.001s在MySQL8上需要108s。查看mysql 8上“发送数据”的执行统计占100%。为什么?
SELECT r.roadid
FROM geocoder.osm_road r
WHERE mbrintersects(ST_Buffer(ST_GEOMETRYFROMTEXT('Point(-1.91289 52.58260)',0),0.0005), r.geometry)
我们有许多不同的空间查询,它们都是这样运行的,但特别是MBR相交和stïU相交看起来非常慢。更改为st_contains(如果可能)会有显著的改进(即上面的操作需要3秒而不是108秒),但这不适合许多查询,并且仍然比5.7中的慢很多。
Show Create Table for 5.7
CREATE TABLE `osm_road` (
`roadid` bigint(20) NOT NULL,
`reference` varchar(20) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`dictionary` longtext,
`road_speed_limit` tinyint(4) unsigned NOT NULL,
`road_speed_unitid` tinyint(1) NOT NULL,
`road_type` tinyint(4) NOT NULL,
`is_toll_road` bit(1) NOT NULL DEFAULT b'0',
`is_one_way` bit(1) NOT NULL DEFAULT b'0',
`countryid` smallint(6) DEFAULT NULL,
`geometry` geometry NOT NULL,
`datemodified` datetime DEFAULT CURRENT_TIMESTAMP,
`datecreated` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`roadid`),
UNIQUE KEY `id_roadid` (`roadid`),
SPATIAL KEY `ix_road_geometry` (`geometry`),
KEY `ix_road_reference` (`reference`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AVG_ROW_LENGTH=207
Show Create Table for 8.0.11
CREATE TABLE `osm_road` (
`roadid` bigint(20) NOT NULL,
`reference` varchar(20) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`dictionary` longtext,
`road_speed_limit` tinyint(4) unsigned NOT NULL,
`road_speed_unitid` tinyint(1) NOT NULL,
`road_type` tinyint(4) NOT NULL,
`is_toll_road` bit(1) NOT NULL DEFAULT b'0',
`is_one_way` bit(1) NOT NULL DEFAULT b'0',
`countryid` smallint(6) DEFAULT NULL,
`geometry` geometry NOT NULL /*!80003 SRID 0 */,
`datemodified` datetime DEFAULT CURRENT_TIMESTAMP,
`datecreated` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`roadid`),
UNIQUE KEY `id_roadid` (`roadid`),
KEY `ix_road_reference` (`reference`),
SPATIAL KEY `ix_road_geometry` (`geometry`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AVG_ROW_LENGTH=207
显示osmèu路的索引(5.7)
Table,Non_unique,Key_name,Seq_in_index,Column_name,Collation,Cardinality,Sub_part,Packed,Null,Index_type,Comment,Index_comment
osm_road,0,PRIMARY,1,roadid,A,18973144,NULL,NULL,,BTREE,,
osm_road,1,ix_road_geometry,1,geometry,A,18973154,32,NULL,,SPATIAL,,
osm_road,1,ix_road_reference,1,reference,A,199900,NULL,NULL,YES,BTREE,,
显示osmèu路索引(8.0.11)
Table,Non_unique,Key_name,Seq_in_index,Column_name,Collation,Cardinality,Sub_part,Packed,Null,Index_type,Comment,Index_comment,Visible
osm_road,0,PRIMARY,1,roadid,A,16194921,NULL,NULL,,BTREE,,,YES
osm_road,1,ix_road_reference,1,reference,A,86215,NULL,NULL,YES,BTREE,,,YES
osm_road,1,ix_road_geometry,1,geometry,A,16194921,32,NULL,,SPATIAL,,,YES
显示全局状态(8.0.11)单击此处
显示全局变量(8.0.11)单击此处
--新增2019-01-27
3条答案
按热度按时间bvjveswy1#
我也有类似的问题,答案是确保空间列包含srid。看到了吗https://mysqlserverteam.com/upgrading-to-mysql-8-0-with-spatial-data/. 之后,查询开始使用空间索引,这是以前没有的
ki0zmccv2#
MBRIntersects
以及ST_Intersects
在MySQL8.0中被破坏(在8.0.15中测试),比MySQL5.7慢10倍多。对于我禁用空间索引的使用(使用IGNORE INDEX
,强制执行全表扫描,在一定程度上加快了查询速度。查看此错误报告https://bugs.mysql.com/bug.php?id=94655ohtdti5x3#
退货: