No cache version.

Caching disabled. Default setting for this page:enabled (code DEF204)
If the display is too slow, you can disable the user mode to view the cached version.

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:

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:

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.

  1. mysql> DESCRIBE geom;
  2. +-------+----------+------+-----+---------+----------------+
  3. | Field | Type     | Null | Key | Default | Extra          |
  4. +-------+----------+------+-----+---------+----------------+
  5. | fid   | int(11)  |      | PRI | NULL    | auto_increment |
  6. | g     | geometry |      |     |         |                |
  7. +-------+----------+------+-----+---------+----------------+
  8. 2 rows in set (0.00 sec)
  9.  
  10. mysql> SELECT COUNT(*) FROM geom;
  11. +----------+
  12. | count(*) |
  13. +----------+
  14. |    32376 |
  15. +----------+
  16. 1 row in set (0.00 sec)

To add a spatial index on the column g, use this statement:

  1. mysql> ALTER TABLE geom ADD SPATIAL INDEX(g);
  2. Query OK, 32376 rows affected (4.05 sec)
  3. Records: 32376  Duplicates: 0  Warnings: 0

Find a PHP function

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

  1. View the html document Language of the document:en Manuel MySQL : https://dev.mysql.com/

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.

Contents Haut