zoukankan      html  css  js  c++  java
  • Creating Spatial Indexes(mysql 创建空间索引 The used table type doesn't support SPATIAL indexes)

    For MyISAM tables, MySQL 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. The following examples demonstrate how to create spatial indexes:

    • With CREATE TABLE:

      CREATE TABLE geom (g GEOMETRY NOT NULL, SPATIAL INDEX(g)) ENGINE=MyISAM;
      
    • 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 nonspatial indexing of spatial columns, the engine creates a B-tree index. A B-tree index on spatial values will be useful for exact-value lookups, but not for range scans.

    For more information on indexing spatial columns, see Section 13.1.8, “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.

    mysql> DESCRIBE geom;
    +-------+----------+------+-----+---------+----------------+
    | Field | Type     | Null | Key | Default | Extra          |
    +-------+----------+------+-----+---------+----------------+
    | fid   | int(11)  |      | PRI | NULL    | auto_increment |
    | g     | geometry |      |     |         |                |
    +-------+----------+------+-----+---------+----------------+
    2 rows in set (0.00 sec)
    
    mysql> SELECT COUNT(*) FROM geom;
    +----------+
    | count(*) |
    +----------+
    |    32376 |
    +----------+
    1 row in set (0.00 sec)
    

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

    mysql> ALTER TABLE geom ADD SPATIAL INDEX(g);
    Query OK, 32376 rows affected (4.05 sec)
    Records: 32376  Duplicates: 0  Warnings: 0
  • 相关阅读:
    用Sqoop实现数据HDFS到mysql到Hive
    hdfs的文件结构
    搭建Hadoop-1.2.1&hbase-0.94.17&hive-0.9.0&centos6.8_x64集群
    缩减表空间碎片
    MySQL8.0.12源码编译安装_centos7.3
    Mysql8.0.18的源码安装
    mysql5.7.31二进制安装_centos7
    个人windows开发环境风格
    linux shell中那些奇奇怪怪的语法
    关于上线的一些事儿
  • 原文地址:https://www.cnblogs.com/mfryf/p/3455276.html
Copyright © 2011-2022 走看看