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

Creating Spatial Indexes(mysql 创建空间索引 The used table type doesn't support SPATIAL indexes)的更多相关文章

  1. mysql The used table type doesn’t support FULLTEXT indexes 解决方案 (phpstudy 会出现),coten不会

    mysql The used table type doesn't support FULLTEXT indexes 是不支持全文索引,解决方案: 1.停掉mysql服务2.打开my.ini,搜索de ...

  2. #1214 - The used table type doesn't support FULLTEXT indexes解决办法

    #1214 - The used table type doesn't support FULLTEXT indexes报此错误的原因是:InnoDB不支持FULLTEXT类型的索引. 网上的解决办法 ...

  3. [Err] 1214 - The used table type doesn't support FULLTEXT indexes

    -- -- Table structure for table `film_text` -- -- InnoDB added FULLTEXT support in 5.6.10. If you us ...

  4. Mysql创建表时报错Table doesn't exist解决办法

    最近做项目时,本地数据库出了毛病,PHPMyadmin中有几张表不见了,我想应该是误删了吧,于是准备重新建一张表,可是问题出现了,sql报错,说表不存在... 什么鬼!就是因为表不存在我才要创建的好吗 ...

  5. mysql创建索引以及对索引的理解

    创建表的时候创建索引   创建索引是指在某个表的一列或多列上建立一个索引,以便提高对表的访问速度.创建索引有3种方式,这3种方式分别是创建表的时候创建索引.在已经存在的表上创建索引和使用ALTER T ...

  6. mysql创建/删除表的例子

    创建表 简单的方式 CREATE TABLE person ( number INT(11), name VARCHAR(255), birthday DATE ); 或者是 CREATE TABLE ...

  7. mysql创建和删除表

    创建表 简单的方式 CREATE TABLE person ( ), name ), birthday DATE ); 或者是 CREATE TABLE IF NOT EXISTS person ( ...

  8. mysql创建表分区

    MySQL创建表分区 create table erp_bill_index( id int primary key auto_increment, addtime datetime ); inser ...

  9. mysql对GIS空间数据的支持,包括创建空间索引

    CREATE TABLE tb_geo( id INT PRIMARY KEY AUTO_INCREMENT, NAME ) NOT NULL, pnt POINT NOT NULL, SPATIAL ...

随机推荐

  1. C函数调用与栈--代码真相

    前面详细的说了,C函数调用的过程中,栈的变化情况的原理部分,这里在看一下汇编代码的真正的实现. 有关前面的那一片博客,主要记住的就是函数调用时栈的变化,4+3+2的步骤: (1)设置栈帧边界 (2)开 ...

  2. 运行PHP

    /usr/local/php/bin/php /home/www/index.php

  3. poj 2661 Factstone Benchmark

    /** 大意: 求m!用2进制表示有多少位 m! = 2^n 两边同时取对数 log2(m!) = n 即 log2(1) + log2(2)+log2(3)+log2(4)...+log2(m) = ...

  4. 「操作系统」:The most useful condition codes

    CF: Carry Flag.The most recent operation generated a carry out of the most significant bit. Used to ...

  5. hadoop的WordCount样例

    package cn.lmj.mapreduce; import java.io.IOException; import java.util.Iterator; import org.apache.h ...

  6. SQL Server 2008 还原数据库

    1.得到数据库备份文件,怎么得到的,[能够看这里]~ 2.把备份文件加个.bak 的后缀,比如: 3.打开SQL , 你能够新建一个空数据库 , 或者利用原有的数据库 , 点击右键>>任务 ...

  7. 密钥登录linux

    一.linux 主机A登录linux主机B 在/etc/hosts文件下加入:(做硬解析) 192.168.1.60 u60 #设置u60为主机名 在节点A上创建RSA秘钥:(A上生成A主机密钥) # ...

  8. Apple Watch程序开发30分钟秒懂

    苹果公司Apple Watch智能手表正在备受追捧,迅速掌握Apple Watch的APP架构,环境搭建,及实例开发将会让开发者占尽先机.我赢职场全国首发,30分钟玩转Apple Watch应用开发实 ...

  9. spark sql 以JDBC为数据源

    一.环境准备: 安装mysql后,进入mysql命令行,创建测试表.数据: 将 mysql-connector-java 的jar文件拷贝到 \spark_home\lib\下,你可以使用最新版本,下 ...

  10. C语言结构体变量内存分配与地址对齐

    地址对齐简单来说就是为了提高访问内存的速度. 数组的地址分配比较简单,由于数据类型相同,地址对齐是一件自然而然的事情. 结构体由于存在不同基本数据类型的组合,所以地址对齐存在不同情况,但总体来说有以下 ...