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张表)
注:使用的库中表太多,对元数据查询还是有影响,故建议一个库不要存太多表
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)