Rechercher dans le manuel MySQL
11.5.10 Creating 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:
With
CREATE TABLE
:With
ALTER TABLE
:With
CREATE INDEX
:
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, see Section 11.5.1, “Spatial Data Types”, and Section 8.3.3, “SPATIAL Index Optimization”.
For more information on indexing spatial columns, see Section 13.1.15, “CREATE INDEX Syntax”.
To drop spatial indexes, use ALTER
TABLE
or DROP INDEX
:
With
ALTER TABLE
:With
DROP INDEX
:
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.
- +-------+----------+------+-----+---------+----------------+
- +-------+----------+------+-----+---------+----------------+
- +-------+----------+------+-----+---------+----------------+
- +----------+
- +----------+
- | 32376 |
- +----------+
To add a spatial index on the column g
, use
this statement:
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-creating-spatial-indexes.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.