閱讀786 返回首頁    go iPhone_iPad_Mac_手機_平板_蘋果apple


CREATE INDEX__數據定義語言_SQL語法參考_雲數據庫 OceanBase-阿裏雲

索引是創建在表上的,對數據庫表中一列或多列的值進行排序的一種結構。其作用主要在於提高查詢的速度,降低數據庫係統的性能開銷。

OceanBase中,新創建的索引需要等待一次每日合並後,才生效。

格式

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 | SNAPPY1.0 | ZLIB_1.0}'
    | BLOCK_SIZE [=] size
    | STORING(columname_list)
    | index_using_algorithm

columname_list: 
    colname [, colname…]

index_col_name: 
     colname [ASC | DESC] 
  • index_col_name中,每個列名後都支持ASC(升序)和DESC(降序)。默認就為升序。

  • 本語句建立索引的排列方式為:首先以index_col_name中第一個列的值排序;該列值相同的記錄,按下一列名的值排序;以此類推。

  • 執行“SHOW INDEX FROM tblname”可以查看創建的索引。

  • “index_option”中,可以指定GLOBAL,LOCAL關鍵字,表述全局或局部索引。默認是GLOBAL index. 創建帶有Parition的表時index一定要加LOCAL關鍵字。如果沒有加,係統將報錯。多個index option以空格分隔。

  • 使用可選字段STORING,表示索引表中冗餘存儲某些列,以提高係統查詢係統。(為OceanBase數據庫特有

說明: OceanBase內部數據以b樹為索引。

舉例

Oceanbase>CREATE TABLE test (c1 int primary key, c2 varchar(10));
Query OK, 0 rows affected (0.10 sec)

Oceanbase>create index test_index on test(c1, c2 desc) using hash;
Query OK, 0 rows affected (0.04 sec)

Oceanbase>show index from test;
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-------------+---------------+
| Table | Non_unique | Key_name   | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment     | Index_comment |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-------------+---------------+
| test  |          0 | PRIMARY    |            1 | c1          | A         |        NULL | NULL     | NULL   |      | BTREE      | available   |               |
| test  |          1 | test_index |            1 | c1          | A         |        NULL | NULL     | NULL   |      | BTREE      | unavailable |               |
| test  |          1 | test_index |            2 | c2          | A         |        NULL | NULL     | NULL   | YES  | BTREE      | unavailable |               |
+-------+------------+------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+-------------+---------------+
3 rows in set (0.00 sec)

最後更新:2016-11-24 11:23:47

  上一篇:go RENAME TABLE__數據定義語言_SQL語法參考_雲數據庫 OceanBase-阿裏雲
  下一篇:go DROP INDEX__數據定義語言_SQL語法參考_雲數據庫 OceanBase-阿裏雲