

© 2025 by The Clinic. Powered and secured by Wix
MySQL:
SPATIAL INDEXES
For InnoDB and MyISAM tables, MySQL can create spatial indexes using
syntax similar to that for creating regular indexes, but using the
SPATIAL keyword. Columns in spatial indexes must be declared NOT NULL.
The following examples demonstrate how to create spatial indexes:
o With CREATE TABLE:
CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326, SPATIAL INDEX(g));
o With ALTER TABLE:
CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326);
ALTER TABLE geom ADD SPATIAL INDEX(g);
o With CREATE INDEX:
CREATE TABLE geom (g GEOMETRY NOT NULL SRID 4326);
CREATE SPATIAL INDEX g ON geom (g);
SPATIAL INDEX creates an R-tree index. For storage engines that support
nonspatial indexing of spatial columns, the engine creates a B-tree
index. A B-tree index on spatial values is useful for exact-value
lookups, but not for range scans.
The optimizer can use spatial indexes defined on columns that are
SRID-restricted. For more information.
.
For more information on indexing spatial columns, see [HELP CREATE
INDEX].
To drop spatial indexes, use ALTER TABLE or DROP INDEX:
o With ALTER TABLE:
ALTER TABLE geom DROP INDEX g;
o With DROP INDEX:
DROP INDEX g ON geom;
Example: Suppose that a table geom contains more than 32,000
geometries, which are stored in the column g of type GEOMETRY. The
table also has an AUTO_INCREMENT column fid for storing object ID
values.
Example