Warning
Error Code:
3674
MySQL Error 3674: Spatial Index SRID Missing
Description
This warning indicates that MySQL's query optimizer cannot utilize an existing spatial index on a column because the column lacks a Spatial Reference System Identifier (SRID). Consequently, queries involving spatial data on this column may perform slower as the optimizer must resort to full table scans or less efficient methods. It typically occurs when querying spatial data without proper SRID configuration.
Error Message
The spatial index on column '%s' will not be used by the query optimizer since the column does not have an SRID attribute. Consider adding an SRID attribute to the column.
Known Causes
3 known causesMissing SRID Attribute at Column Creation
The spatial column was initially defined without explicitly specifying an SRID attribute, preventing the query optimizer from leveraging SRID-aware indexing.
Spatial Index on Generic Geometry Column
An index was created on a spatial column defined using a generic `GEOMETRY` type without an associated SRID, rendering the index ineffective for SRID-specific optimizations.
Data Migration Omission
During data migration or import processes, the SRID attribute might have been overlooked or stripped from the spatial column definitions, leading to its absence.
Solutions
3 solutions available1. Add SRID to Existing Spatial Column medium
Modify the table to include the SRID attribute for the spatial column.
1
Identify the table and the spatial column causing the error. You can find this information in the error message itself (e.g., '%s' will be the column name).
2
Determine the correct SRID for your spatial data. Common SRIDs include 0 (for Cartesian coordinates, often used for internal calculations) and specific EPSG codes for geographic coordinate systems (e.g., 4326 for WGS 84). Consult your data source or GIS documentation if unsure.
3
Alter the table to add the SRID attribute to the spatial column. Replace `your_table_name`, `your_spatial_column_name`, and `your_srid_value` with your actual values.
ALTER TABLE your_table_name MODIFY COLUMN your_spatial_column_name GEOMETRY SRID your_srid_value;
4
Verify that the SRID has been added correctly by describing the table.
DESCRIBE your_table_name;
5
If a spatial index already exists on this column, it should automatically start being used after the SRID is added. If not, you might need to re-create or rebuild the spatial index.
2. Recreate Spatial Index with SRID medium
Drop and re-create the spatial index, ensuring the SRID is specified.
1
Identify the table and the spatial column (e.g., 'your_spatial_column_name') and the associated spatial index name (often the same as the column name or based on it).
2
Drop the existing spatial index. Replace `your_table_name` and `your_spatial_index_name`.
DROP INDEX your_spatial_index_name ON your_table_name;
3
Re-create the spatial index, explicitly specifying the SRID. Replace `your_spatial_index_name`, `your_table_name`, `your_spatial_column_name`, and `your_srid_value`.
CREATE SPATIAL INDEX your_spatial_index_name ON your_table_name (your_spatial_column_name) USING BTREE WITH SYSTEM VERSIONING, SRID your_srid_value;
4
Confirm the index has been created with the SRID attribute.
SHOW INDEX FROM your_table_name;
3. Define Spatial Column with SRID During Table Creation easy
Ensure new tables with spatial data define the SRID from the outset.
1
When creating a new table that will contain spatial data, define the spatial column with the `SRID` attribute. Replace `your_table_name`, `your_spatial_column_name`, and `your_srid_value`.
CREATE TABLE your_table_name (
id INT AUTO_INCREMENT PRIMARY KEY,
your_spatial_column_name GEOMETRY SRID your_srid_value
);
2
After creating the table, add a spatial index to the column, specifying the SRID if it wasn't implicitly handled by the column definition (though it usually is).
CREATE SPATIAL INDEX idx_your_spatial_column_name ON your_table_name (your_spatial_column_name);