Hcatalog 简明教程

HCatalog - Indexes

Creating an Index

索引实际上只是表某个特定列上的指针。创建索引是指在表的特定列上创建一个指针。其语法如下:

An Index is nothing but a pointer on a particular column of a table. Creating an index means creating a pointer on a particular column of a table. Its syntax is as follows −

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 (...)]

Example

让我们举一个例子来理解索引的概念。使用我们先前使用过的、包含字段 Id、Name、Salary、Designation 和 Dept 的相同 employee 表。在 employee 表的 salary 列上创建一个名为 index_salary 的索引。

Let us take an example to understand the concept of index. Use the same employee table that we have used earlier with the fields Id, Name, Salary, Designation, and Dept. Create an index named index_salary on the salary column of the employee table.

以下查询创建了一个索引:

The following query creates an index −

./hcat –e "CREATE INDEX inedx_salary ON TABLE employee(salary)
AS 'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler';"

它是 salary 列的指针。如果该列被修改,则更改将使用索引值进行存储。

It is a pointer to the salary column. If the column is modified, the changes are stored using an index value.

Dropping an Index

以下语法用于删除索引:

The following syntax is used to drop an index −

DROP INDEX <index_name> ON <table_name>

以下查询将删除索引 index_salary −

The following query drops the index index_salary −

./hcat –e "DROP INDEX index_salary ON employee;"