On MyISAM and Aria tables, as well as on InnoDB tables from MariaDB 10.2.2, MariaDB can create spatial indexes (an R-tree index) using syntax similar to that for creating regular indexes, but extended with the SPATIAL
keyword. Currently, columns in spatial indexes must be declared NOT NULL
.
Spatial indexes can be created when the table is created, or added after the fact like so:
CREATE TABLE geom (g GEOMETRY NOT NULL, SPATIAL INDEX(g));
ALTER TABLE geom ADD SPATIAL INDEX(g);
CREATE SPATIAL INDEX sp_index ON geom (g);
SPATIAL INDEX
creates an R-tree
index. For storage engines that support non-spatial 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.
For more information on indexing spatial columns, see CREATE INDEX.
To drop spatial indexes, use ALTER TABLE or DROP INDEX:
ALTER TABLE geom DROP INDEX g;
DROP INDEX sp_index ON geom;
Before MariaDB 10.4.3, InnoDB's spatial indexes could not be encrypted. If an InnoDB table was encrypted and if it contained spatial indexes, then those indexes would be unencrypted.
In MariaDB 10.4.3 and later, if innodb_checksum_algorithm
is set to full_crc32
or strict_full_crc32
, and if the table does not use ROW_FORMAT=COMPRESSED
, then InnoDB spatial indexes will be encrypted if the table is encrypted.
See MDEV-12026 for more information.
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/spatial-index/