SPATIAL

You are viewing an old version of this article. View the current version here.

Description:

MariaDB can create spatial indexes 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:

  • with CREATE TABLE:
    CREATE TABLE geom (g GEOMETRY NOT NULL, SPATIAL INDEX(g));
    
  • with ALTER TABLE:
    ALTER TABLE geom ADD SPATIAL INDEX(g);
    
  • with CREATE INDEX:
    CREATE SPATIAL INDEX sp_index ON geom (g);
    

For MyISAM tables, 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:

  • with ALTER TABLE:
    ALTER TABLE geom DROP INDEX g;
    
  • with DROP INDEX:
    DROP INDEX sp_index ON geom;
    

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.