hive中drop表效率低

问题描述: 
使用hive时,drop表很慢,一张空表都需要90s左右 
检查: 
--------检查hive日志,无报错信息 
--------检查主机资源消耗情况,正常无瓶颈 
--------检查mysql日志,无错误提示 
--------检查mysql慢日志(slow.log),发现在drop表时,会在元数据库中进行select,并且时间消耗接近于drop表的时间 
问题分析: 
1、hive在drop表的时候,会去元数据搜索到这张表,故需要进行select 
2、通过explain检查select,发现有全表扫描记录,分析是没有添加相关索引 
问题处理: 
对元数据库的表添加相关索引,索引如下: 
use hivedb; 
create index ind_part_name_tbl_id on partitions(part_name,tbl_id); 
create index ind_tbl_name on tbls (tbl_name); 
create index ind_tbl_id on partitions (tbl_id); 
create index ind_tbl_integer_idx on partition_keys (tbl_id,integer_idx); 
create index ind_cd_integer_idx on columns_v2 (cd_id,integer_idx); 
create index ind_name on dbs (name); 
检查新增索引是否添加 
show index from partitions; 
show index from tbls; 
show index from partition_keys; 
show index from columns_v2; 
show index from dbs; 

重新drop测试结果: 
通过建立的空表再drop时,时间只需不到3秒时间(所使用的库内有4.2W张表) 

注:使用的库中表太多,对元数据查询还是有影响,故建议一个库不要存太多表

posted @ 2022-02-21 22:48  Harda  阅读(728)  评论(0编辑  收藏  举报