結構體

CREATE INDEX index_name
ON TABLE base_table_name (col_name, ...)
AS 'index.handler.class.name'
[WITH DEFERRED REBUILD]
[IDXPROPERTIES (property_name=property_value, ...)]
[IN TABLE index_table_name]
[PARTITIONED BY (col_name, ...)]
[
 [ ROW FORMAT ...] STORED AS ...
 | STORED BY ...
]
[LOCATION hdfs_path]
[TBLPROPERTIES (...)]

例:

CREATE INDEX inedx_salary ON TABLE employee(salary) AS 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler' WITH DEFERRED REBUILD;

改變指數

ALTER INDEX index_name ON table_name [PARTITION(...)] REBUILD

掉落指數

DROP INDEX <index_name> ON <table_name>

如果在 CREATE INDEX 上指定了 WITH DEFERRED REBUILD,則新建立的索引最初為空(無論表是否包含任何資料)。

ALTER INDEX REBUILD 命令可用於為所有分割槽或單個分割槽構建索引結構。