MySQL permits creation of MySQL允许在非空几何值列上创建空间索引(请参阅第11.4.10节,“创建空间索引”)。SPATIAL
indexes on NOT NULL
geometry-valued columns (see Section 11.4.10, “Creating Spatial Indexes”). The optimizer checks the 优化器检查索引列的SRID属性,以确定要用于比较的空间引用系统(SRS),并使用适合SRS的计算。SRID
attribute for indexed columns to determine which spatial reference system (SRS) to use for comparisons, and uses calculations appropriate to the SRS. (Prior to MySQL 8.0, the optimizer performs comparisons of (在MySQL 8.0之前,优化器使用笛卡尔计算执行SPATIAL
index values using Cartesian calculations; the results of such operations are undefined if the column contains values with non-Cartesian SRIDs.)SPATIAL
索引值的比较;如果列包含具有非笛卡尔SRID的值,则此类操作的结果是未定义的。)
For comparisons to work properly, each column in a 为了使比较正常工作,SPATIAL
index must be SRID-restricted. SPATIAL
索引中的每一列都必须受到SRID限制。That is, the column definition must include an explicit 也就是说,列定义必须包含显式SRID
attribute, and all column values must have the same SRID.SRID
属性,并且所有列值必须具有相同的SRID
。
The optimizer considers 优化器只考虑SRID限制列的SPATIAL
indexes only for SRID-restricted columns:SPATIAL
索引:
Indexes on columns restricted to a Cartesian SRID enable Cartesian bounding box computations.限制为笛卡尔SRID的列上的索引启用笛卡尔边界框计算。
Indexes on columns restricted to a geographic SRID enable geographic bounding box computations.限制为地理SRID的列上的索引支持地理边界框计算。
The optimizer ignores 优化器忽略没有SPATIAL
indexes on columns that have no SRID
attribute (and thus are not SRID-restricted). SRID
属性(因此不受SRID限制)的列上的SPATIAL
索引。MySQL still maintains such indexes, as follows:MySQL仍然维护这样的索引,如下所示:
They are updated for table modifications (它们会因表修改(INSERT
, UPDATE
, DELETE
, and so forth). INSERT
、UPDATE
、DELETE
等)而更新。Updates occur as though the index was Cartesian, even though the column might contain a mix of Cartesian and geographical values.即使该列可能包含笛卡尔值和地理值的混合值,也会像索引是笛卡尔值一样进行更新。
They exist only for backward compatibility (for example, the ability to perform a dump in MySQL 5.7 and restore in MySQL 8.0). 它们的存在只是为了向后兼容(例如,在MySQL 5.7中执行转储,在MySQL 8.0中执行恢复)。Because 因为没有SRID限制的列上的SPATIAL
indexes on columns that are not SRID-restricted are of no use to the optimizer, each such column should be modified:SPATIAL
索引对优化器没有任何用处,所以应该修改每一个这样的列:
Verify that all values within the column have the same SRID. 验证列中的所有值是否具有相同的SRID。To determine the SRIDs contained in a geometry column 要确定几何体列col_name
, use the following query:col_name
中包含的srid,请使用以下查询:
SELECT DISTINCT ST_SRID(col_name
) FROMtbl_name
;
If the query returns more than one row, the column contains a mix of SRIDs. 如果查询返回多行,则该列包含SRID的混合。In that case, modify its contents so all values have the same SRID.在这种情况下,请修改其内容,使所有值具有相同的SRID。
Redefine the column to have an explicit 重新定义列以具有显式SRID
attribute.SRID
属性。
Recreate the 重新创建SPATIAL
index.SPATIAL
索引。