更新时间:2022-09-30 GMT+08:00

REGISTER INDEX TABLE

命令功能

REGISTER INDEX TABLE命令用于将索引表注册到主表。

命令语法

REGISTER INDEX TABLE indextable_name ON db_name.maintable_name;

参数描述

表1 REFRESH INDEX TABLE参数描述

参数

描述

db_name

数据库名。若未指定,则选择当前数据库。

indextable_name

索引表名。

maintable_name

主表名。

注意事项

在执行此命令之前,使用REFRESH TABLE将主表和二级所索引表都注册到Hive元数据中。

示例

create database productdb;

use productdb;

CREATE TABLE productSalesTable(a int,b string,c string) stored as carbondata;

create index productNameIndexTable on table productSalesTable(c) as 'carbondata';

insert into table productSalesTable select 1,'a','aaa';

create database productdb2;

使用hdfs命令将productdb数据库下的productSalesTable和productNameIndexTable 拷贝到productdb2。

refresh table productdb2.productSalesTable ;

refresh table productdb2.productNameIndexTable ;

explain select * from productdb2.productSalesTable where c = 'aaa'; //可以发现该查询命令没有使用索引表

REGISTER INDEX TABLE productNameIndexTable ON productdb2.productSalesTable;

explain select * from productdb2.productSalesTable where c = 'aaa'; //可以发现该查询命令使用了索引表

系统响应

通过运行该命令,索引表会被注册到主表。