geo_index.md 994 字节
Newer Older
M
Mars Liu 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# 几何索引

Goods 数据库中有一个 shop 表,其中包含如下字段:

```mysql
create table shop (
    id int primary key auto_increment,
    location GEOMETRY
      -- ...
)
```

现在 Joe 要给 location 字段加上几何索引,他应该怎么做?

M
Mars Liu 已提交
15 16
<hr/>

M
Mars Liu 已提交
17
点击进入[MySQL实战练习环境](https://mydev.csdn.net/product/pod/new?image=cimg-centos7-skilltreemysql&connect=auto&create=auto&utm_source=skill)
M
Mars Liu 已提交
18 19
* `show databases` 列出所有数据库
* `show tables` 列出所有表
M
Mars Liu 已提交
20

M
Mars Liu 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
## 答案

```mysql
alter table shop modify location  GEOMETRY not null;
alter table shop add INDEX geo_index(location);
```

## 选项

### A

```mysql
alter table shop add INDEX geo_index(location);
```

### B

```mysql
alter table shop add INDEX location;
```

### C

```mysql
alter table shop modify location  GEOMETRY not null;
alter table shop add INDEX location;
```

### D

```mysql
alter table shop modify location  GEOMETRY not null;
alter table shop add INDEX location;
```