跳到主要内容
版本:Candidate-4.0

CREATE INDEX

功能

创建索引。

您可以创建以下索引:

有关创建这些索引的详细说明和示例,请参阅上述对应的教程。

提示

该操作需要对应表的 ALTER 权限。请参考 GRANT 为用户赋权。

语法

CREATE INDEX index_name ON table_name (column_name) 
[USING { BITMAP | NGRAMBF | GIN | VECTOR } ]
[(index_property)]
[COMMENT '<comment>']

参数说明

参数必选说明
index_name索引名称,命名要求参见系统限制。在同一张表中不能创建名称相同的索引。
table_name表名。
column_name创建索引的列名。执行一次该语句只能为某一列创建索引,且同一列只能创建一个索引。
USING要创建索引的类型。有效值:
  • BITMAP (默认值)
  • NGRAMBF
  • GIN
  • VECTOR
index_property要创建的索引的属性。对于 NGRAMBFGINVECTOR,您必须指定相应的属性。有关详细说明,请参阅相应的教程。
COMMENT索引备注。

示例

例如有一张表 sales_records,其建表语句如下:

CREATE TABLE sales_records
(
record_id int,
seller_id int,
item_id int
)
DISTRIBUTED BY hash(record_id)
PROPERTIES (
"replication_num" = "3"
);

为表 sales_records 中的 item_id 列创建 bitmap 索引,索引名称为 index

CREATE INDEX index ON sales_records (item_id) USING BITMAP COMMENT '';

CREATE INDEX index ON sales_records (item_id);

相关操作