Move the docs folder
This commit is contained in:
committed by
LINxiansheng
parent
7c6dcc6712
commit
d42f317422
102
docs/docs-cn/10.sql-reference/5.sql-statement/12.create-index.md
Normal file
102
docs/docs-cn/10.sql-reference/5.sql-statement/12.create-index.md
Normal file
@ -0,0 +1,102 @@
|
||||
CREATE INDEX
|
||||
=================================
|
||||
|
||||
|
||||
|
||||
描述
|
||||
-----------
|
||||
|
||||
该语句用来创建索引。索引是创建在表上的,对数据库表中一列或多列的值进行排序的一种结构。其作用主要在于提高查询的速度,降低数据库系统的性能开销。
|
||||
|
||||
格式
|
||||
-----------
|
||||
|
||||
```javascript
|
||||
CREATE [UNIQUE] INDEX indexname
|
||||
ON tblname (index_col_name,...)
|
||||
[index_type] [index_options]
|
||||
index_type:
|
||||
USING BTREE
|
||||
|
||||
index_options:
|
||||
index_option [index_option...]
|
||||
|
||||
index_option:
|
||||
GLOBAL | LOCAL
|
||||
| COMMENT 'string'
|
||||
| COMPRESSION [=] {NONE | LZ4_1.0 | LZO_1.0 | SNAPPY_1.0 | ZLIB_1.0}
|
||||
| BLOCK_SIZE [=] size
|
||||
| STORING(columname_list)
|
||||
| VISIBLE | INVISIBLE
|
||||
|
||||
index_col_name:
|
||||
colname [(length)] [ASC | DESC]
|
||||
|
||||
columname_list:
|
||||
colname [, colname...]
|
||||
```
|
||||
|
||||
|
||||
|
||||
参数解释
|
||||
-------------
|
||||
|
||||
|
||||
|
||||
| **参数** | **描述** |
|
||||
|-----------------|---------------------------------------------------------------------------------------------------------------------------|
|
||||
| indexname | 指定要创建的索引名称。 |
|
||||
| tblname | 指过索引所属的表名。 |
|
||||
| index_col_name | 指定索引的列名,每个列名后都支持ASC(升序),不支持DESC(降序)。默认为升序。 建立索引的排序方式为:首先以index_col_name中第一个列的值排序;该列值相同的记录,按下一列名的值排序;以此类推。 |
|
||||
| index_type | 索引类型,只支持USING BTREE,以B树为索引。 |
|
||||
| UNIQUE | 指定为唯一索引。 |
|
||||
| index_option | 指定索引选项,多个index_option以空格分隔。 |
|
||||
| GLOBAL \| LOCAL | 指定该索引是全局索引或局部索引,默认是GLOBAL。 |
|
||||
| COMMENT | 指定注释。 |
|
||||
| COMPRESSION | 指定压缩算法。 |
|
||||
| BLOCK_SIZE | 指定微块大小。 |
|
||||
| STORING | 表示索引表中冗余存储某些列,以提高系统查询性能。 |
|
||||
|
||||
|
||||
|
||||
示例
|
||||
-----------
|
||||
|
||||
1. 执行以下命令,创建表test。
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
```javascript
|
||||
CREATE TABLE test (c1 int primary key, c2 VARCHAR(10));
|
||||
```
|
||||
|
||||
|
||||
|
||||
2. 执行以下命令,创建表test的索引。
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
```javascript
|
||||
CREATE INDEX test_index ON test (c1, c2 DESC);
|
||||
```
|
||||
|
||||
|
||||
|
||||
3. 执行以下命令,查看表test的索引。
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
```javascript
|
||||
SHOW INDEX FROM test;
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user