Hive和mysql等数据库一样,也有视图的概念,视图实际上是一张虚拟的表,是对数据的逻辑表示,只是一种显示的方式,主要的作用是:
1、视图能够简化用户的操作
2、视图使用户能以多钟角度看待同一数据
3、视图对重构数据库提供了一定程度的逻辑独立性
4、视图能够对机密数据提供安全保护
5、适当的利用视图可以更清晰的表达查询
如何创建一个视图?
create view t_view as select * from otherTbl;
关于视图的几点说明:
1、只有视图的定义,没有相应的物理结构
也就是说只有在metastore中有和hdfs中的映射关系,在hdfs中没有相应的文件夹
2、操作
可以把视图当做表的一个延伸,所以对hive表的各种操作,在视图上就有。
索引
1.创建索引
create index t1_index on table t1(stu_name) as'org.apache.hadoop.hive.ql.index.compact.CompactIndexHandler'with deferred rebuild in table t1_index_table;
as 指定索引器
2.重建索引
alter index t1_index on t1 rebuild;
3.显示索引
show formatted index on t1;
4.删除索引
drop index if exists t1_index on t1;