HiveSql调优系列之Hive严格模式,如何合理使用Hive严格模式
综述
在同样的集群运行环境中,hive调优有两种方式,即参数调优和sql调优。
本篇讲涉及到的Hive严格模式。
前两天在优化一个前人遗留下的sql,发现关于严格模式参数是这样使用的,严重错误。
set hive.strict.checks.cartesian.product=flase;
set hive.mapred.mode=nonstrict;
而且我发现在使用参数上,无论sql大小直接贴一堆参数,类似这样。
set hive.exec.parallel=true;
set hive.exec.parallel.thread.number=16;
set hive.merge.mapfiles = true;
set hive.merge.mapredfiles = true;
set hive.merge.size.per.task=256000000;
set hive.merge.smallfiles.avgsize = 256000000;
set mapred.max.split.size=1024000000;
set mapred.min.split.size.per.node=1024000000;
set mapred.min.split.size.per.rack=1024000000;
set hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat;
set hive.join.emit.interval = 2000;
set hive.mapjoin.size.key = 20000;
set hive.mapjoin.cache.numrows = 20000;
set hive.exec.reducers.bytes.per.reducer=2000000000;
set hive.exec.reducers.max=999;
set hive.map.aggr=true;
set hive.groupby.mapaggr.checkinterval=100000;
set hive.auto.convert.join = true;
set hive.exec.dynamic.partition.mode = nonstrict;
set hive.exec.dynamic.partition = true;
set hive.cli.print.header=true;
set hive.resultset.use.unique.column.names=false;
set mapreduce.reduce.memory.mb=4096;
set mapreduce.reduce.java.opts=-Xmx4096m;
set mapred.max.split.size=1024000000;
set mapred.min.split.size.per.node=1024000000;
set mapred.min.split.size.per.rack=1024000000;
优化是优化了,但是我看到了优化的无目标性,反而在一定程度上多消耗了计算资源。
于是打算开一个系列文章,Hive SQL调优系列,如何合理的使用参数进行SQL优化,针对什么情况使用哪些参数优化。
本篇先说说严格模式相关参数怎么使用。
正文如下。
1.严格模式
所谓Hive的严格模式,就是为了避免用户提交一些恶意SQL,消耗大量资源进而使得运行环境崩溃做出的一些安全性的限制。
或多或少我们都提交过一些执行很久,集群资源不足的SQL。应该能理解。
前文Hive动态分区详解中有提到过
1.1 参数设置
-- strict 为开启严格模式 nostrict 关闭严格模式
set hive.mapred.mode=strict
1.2 查看参数
通过hive的set 查看指定参数
-- 黑窗口查看Hive模式,以下结果为未开启严格模式
hive> set hive.mapred.mode;
hive.mapred.mode is undefined
1.3 严格模式限制内容及对应参数设置
如果Hive开启严格模式,将会阻止一下三种查询:
a.对分区表查询,where条件中过滤字段没有分区字段;
b.对order by查询,order by的查询不带limit语句。
c.笛卡尔积join查询,join查询语句中不带on条件或者where条件;
以上三种查询情况也有自己单独的参数可以进行控制。
- 分区表查询必须指定分区
-- 开启限制(默认为 false)
set hive.strict.checks.no.partition.filter=true;
- orderby排序必须指定limit
-- 开启限制(默认为false)
set hive.strict.checks.orderby.no.limit=true;
- 限制笛卡尔积运算
-- 开启限制(默认为false)
set hive.strict.checks.cartesian.product=true;
2.实际操作
2.1 分区表查询时必须指定分区
分区表查询必须指定分区的原因:如果该表有大量分区,如果不加限制,在读取时会读取到超出预估的数据量。
-- 测试
create table `lubian` (
`id` string comment 'id',
`name` string comment '姓名'
)
comment 'lubian'
PARTITIONED BY (ymd string)
row format delimited fields terminated by '\t' lines terminated by '\n'
stored as orc;
set hive.strict.checks.no.partition.filter=true;
select * from lubian limit 111;
执行结果
FAILED: SemanticException [Error 10056]:
Queries against partitioned tables without a partition filter are disabled for safety reasons.
If you know what you are doing, please set hive.strict.checks.no.partition.
filter to false and make sure that hive.mapred.mode is not set to 'strict' to proceed.
Note that you may get errors or incorrect results if you make a mistake while using some of the unsafe features.
No partition predicate for Alias "lubian" Table "lubian"
select * from partab where dt='11' limit 111;
Time taken: 0.77 seconds
2.2 order by必须指定limit
order by必须指定limit的主要原因: order by 为全局排序,所有数据只有一个reduceTask来处理,防止单个reduce运行时间过长,而导致任务阻塞
-- 测试
set hive.strict.checks.orderby.no.limit=true;
select * from lubian order by name;
执行结果
FAILED: SemanticException 1:36
Order by-s without limit are disabled for safety reasons.
If you know what you are doing, please set hive.strict.checks.orderby.no.limit to false
and make sure that hive.mapred.mode is not set to 'strict' to proceed.
Note that you may get errors or incorrect results if you make a mistake while using some of the unsafe features..
Error encountered near token 'name'
2.3 限制笛卡尔积
限制笛卡尔积运算原因:笛卡尔积可能会造成数据急速膨胀,例如两个1000条数据表关联,会产生100W条数据。n的平方增长。触发笛卡尔积时,join操作会在一个reduceTask中执行
-- 测试
set hive.strict.checks.cartesian.product=true;
select t1.*,t2.* from lubian as t1
inner join lubian as t2;
执行结果
FAILED: SemanticException Cartesian products are disabled for safety reasons.
If you know what you are doing, please set hive.strict.checks.cartesian.product to false
and make sure that hive.mapred.mode is not set to 'strict' to proceed.
Note that you may get errors or incorrect results
if you make a mistake while using some of the unsafe features.
3.搭配使用
3.1 参数
设置hive严格模式参数如下
set hive.mapred.mode=strict;
set hive.strict.checks.no.partition.filter=true;
set hive.strict.checks.orderby.no.limit=true;
set hive.strict.checks.cartesian.product=true;
以上参数可以使用 set hive.mapred.mode=strict;
默认开启三种情况的严格模式。也可以使用每个限制内容参数开启指定严格校验。
3.2 搭配使用案例
也可以搭配使用,但是使用以下方式就有些问题了:
-- 关闭笛卡尔积运算校验
set hive.strict.checks.cartesian.product=flase;
-- 关闭严格模式
set hive.mapred.mode=nonstrict;
应该是严格模式默认关闭,但仍想对其中一种情况做校验。如下
set hive.mapred.mode=nonstrict;
set hive.strict.checks.cartesian.product=true;
或者严格模式默认开启,但对其中一种不想做校验:
set hive.mapred.mode=strict;
set hive.strict.checks.cartesian.product=false;
以上内容。
按例,欢迎点击此处关注我的个人公众号,交流更多知识。
后台回复关键字 hive,随机赠送一本鲁边备注版珍藏大数据书籍。
HiveSql调优系列之Hive严格模式,如何合理使用Hive严格模式的更多相关文章
- SQL Server性能调优系列
这是关于SQL Server调优系列文章,以下内容基本涵盖我们日常中所写的查询运算的分解以及调优内容项,皆为原创........ 第一个基础模块注重基础内容的掌握,共分7篇文章完成,内容涵盖一系列基础 ...
- SQL Server调优系列基础篇
前言 关于SQL Server调优系列是一个庞大的内容体系,非一言两语能够分析清楚,本篇先就在SQL 调优中所最常用的查询计划进行解析,力图做好基础的掌握,夯实基本功!而后再谈谈整体的语句调优. 通过 ...
- SQL Server调优系列基础篇(常用运算符总结——三种物理连接方式剖析)
前言 上一篇我们介绍了如何查看查询计划,本篇将介绍在我们查看的查询计划时的分析技巧,以及几种我们常用的运算符优化技巧,同样侧重基础知识的掌握. 通过本篇可以了解我们平常所写的T-SQL语句,在SQL ...
- SQL Server调优系列基础篇(联合运算符总结)
前言 上两篇文章我们介绍了查看查询计划的方式,以及一些常用的连接运算符的优化技巧,本篇我们总结联合运算符的使用方式和优化技巧. 废话少说,直接进入本篇的主题. 技术准备 基于SQL Server200 ...
- SQL Server调优系列基础篇(并行运算总结)
前言 上三篇文章我们介绍了查看查询计划的方式,以及一些常用的连接运算符.联合运算符的优化技巧. 本篇我们分析SQL Server的并行运算,作为多核计算机盛行的今天,SQL Server也会适时调整自 ...
- SQL Server调优系列基础篇(并行运算总结篇二)
前言 上一篇文章我们介绍了查看查询计划的并行运行方式. 本篇我们接着分析SQL Server的并行运算. 闲言少叙,直接进入本篇的正题. 技术准备 同前几篇一样,基于SQL Server2008R2版 ...
- SQL Server调优系列基础篇(索引运算总结)
前言 上几篇文章我们介绍了如何查看查询计划.常用运算符的介绍.并行运算的方式,有兴趣的可以点击查看. 本篇将分析在SQL Server中,如何利用先有索引项进行查询性能优化,通过了解这些索引项的应用方 ...
- SQL Server调优系列基础篇(子查询运算总结)
前言 前面我们的几篇文章介绍了一系列关于运算符的介绍,以及各个运算符的优化方式和技巧.其中涵盖:查看执行计划的方式.几种数据集常用的连接方式.联合运算符方式.并行运算符等一系列的我们常见的运算符.有兴 ...
- SQL Server调优系列进阶篇(查询优化器的运行方式)
前言 前面我们的几篇文章介绍了一系列关于运算符的基础介绍,以及各个运算符的优化方式和技巧.其中涵盖:查看执行计划的方式.几种数据集常用的连接方式.联合运算符方式.并行运算符等一系列的我们常见的运算符. ...
随机推荐
- Spring Security自定义认证器
在了解过Security的认证器后,如果想自定义登陆,只要实现AuthenticationProvider还有对应的Authentication就可以了 Authentication 首先要创建一个自 ...
- Servlet之Request和Response 解析
原理 tomcat服务器会根据请求url中的资源路径,创建对应的Servlet的对象 tomcat服务器.会创建request和response对象,request对象中封装请求消息数据. tomca ...
- 【python基础】第05回 数据类型,交互,格式化输出,运算符
上节内容回顾 1.python的注释 # 单行注释 pycharm快捷键:ctrl+? '''多行注释''' """多行注释""" 2.py ...
- word processing in nlp with tensorflow
Preprocessing Tokenizer source code:https://github.com/keras-team/keras-preprocessing/blob/master/ke ...
- bat-设置oracle服务
1.停止oracle所有服务 并将服务设置为手动启动 @echo off echo oracle服务--------停止 net stop OracleVssWriterORCL net stop O ...
- Bitbucket 使用 SSH 拉取仓库失败的问题
问题 在 Bitbucket 使用 Linux 机器上 ssh-keygen 工具生成的公钥作为 API KEY,然后在 Jenkins 里面存储对应的 SSH 私钥,最后执行 Job 的时候,Win ...
- Python: list列表的11个内置方法
先来逼逼两句: 在实际开发中,经常需要将一组(不只一个)数据存储起来,以便后边的代码使用.在VBA中有使用数组,可以把多个数据存储到一起,通过数组下标可以访问数组中的每个元素.Python 中没有数组 ...
- Tapdata 肖贝贝:实时数据引擎系列(四)-关于 Oracle 与 Oracle CDC
摘要:想实现 Oracle 的 CDC,排除掉一些通用的比如全量比对, 标记字段获取之外, 真正的增量形式获取变更, 有三种办法: Logminer .XStream .裸日志解析,但不管哪种方法 ...
- spring-security 配置简介
1.Spring Security 简介 Spring Security 是一个能够基于 Spring 的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在 Spring 应用 ...
- Template -「整体二分」
写的简单.主要是留给自己做复习资料. 「BZOJ1901」Dynamic Rankings. 给定一个含有 \(n\) 个数的序列 \(a_1,a_2 \dots a_n\),需要支持两种操作: Q ...