Hive CBO。 Hive SQL查询错误的错误结果,其中有多个条件在WHERE子句中
我正在 Hive 中运行一个 SQL 查询,在启用和禁用 CBO 的情况下它会给出不同的结果。启用 CBO 时(set hive.cbo.enable=true;),结果是错误的。
先决条件: 安装了 Apache Hadoop 2.10.1 + Apache Hive 2.3.6。 (我尝试使用 Apache Hive 3+ 版本和 Hadoop 3+ 版本重现该问题,它们工作正常。)
重现操作:
1) 在 Hive 中创建表
创建表
样本
(fname
字符串,sname
字符串,sid
字符串)行格式 SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' 存储为 输入格式“org.apache.hadoop.mapred.TextInputFormat”输出格式 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' TBLPROPERTIES('transient_lastDdlTime'='1616020251');
2)在表中插入一些记录,值如下
插入样本值(“PQ”,“F”,“33”);
插入样本值(“RK”,“A”,“11”);
插入样本值(“AZ”、“B”、“22”);
3)检查表格
从样本中选择*;
PQ F 33
RK A 11
AZ B 22
4) 运行以下查询。它应该给出 0 条记录,而不是给出所有记录
从样本中选择 fname,其中 sid 在 ('11') 中,sid 在 ('22') 中;
PQ
RK
AZ
5)当我们在 Hive 中禁用 cbo 时,结果很好
设置 hive.cbo.enable=false;
从样本中选择 fname,其中 sid 在 ('11') 中,sid 在 ('22') 中;
好的 耗时:0.131秒
I am running one SQL query in Hive and it gives different results with CBO enabled and disabled. The results are wrong when CBO is enabled (set hive.cbo.enable=true;).
Prerequisites:
Apache Hadoop 2.10.1 + Apache Hive 2.3.6 installed.
(I tried to reproduce the issue with Apache Hive 3+ version and Hadoop 3+ version and they work fine.)
Actions to reproduce:
1) Create the table in Hive
CREATE TABLE
sample
(fname
string,sname
string,sid
string) ROW FORMAT SERDE
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe' STORED AS
INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat' OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
TBLPROPERTIES ( 'transient_lastDdlTime'='1616020251');
2) Insert some records in the table the below values
insert into sample values ("PQ", "F", "33");
insert into sample values ("RK", "A", "11");
insert into sample values ("AZ", "B", "22");
3) Check the table
select * from sample;
PQ F 33
RK A 11
AZ B 22
4) Run the below query. It should give 0 records, instead it gives all records
select fname from sample where sid in ('11') and sid in ('22');
PQ
RK
AZ
5) The results are good when we disable cbo in Hive
set hive.cbo.enable=false;
select fname from sample where sid in ('11') and sid in ('22');
OK
Time taken: 0.131 seconds
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
错误的结果来自 HivePointLookupOptimizerRule [1] 中的错误简化。这对应于 HIVE-21685 [2] 下记录的错误,该错误已在版本 >= 3.2.0 中修复。
作为解决方法,您可以通过将相应的属性设置为 false 来禁用相应的规则。
设置 hive.optimize.point.lookup=false
[1] https://github.com/apache/hive/blob/62834fbdd3bd4065413b59448759c6a25aa1dbf0/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HivePointLookupOptimizerRule.java
[2 ] <一href="https://issues.apache.org/jira/browse/HIVE-21685" rel="nofollow noreferrer">https://issues.apache.org/jira/browse/HIVE-21685
The wrong results come from a wrong simplification in the HivePointLookupOptimizerRule [1]. This corresponds to the bug logged under HIVE-21685 [2] that was fixed in versions >= 3.2.0.
As a workaround you can disable the respective rule by setting the respective property to false.
set hive.optimize.point.lookup=false
[1] https://github.com/apache/hive/blob/62834fbdd3bd4065413b59448759c6a25aa1dbf0/ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HivePointLookupOptimizerRule.java
[2] https://issues.apache.org/jira/browse/HIVE-21685
数据类型是字符串使用int
,最简单的解决方案是不要使用CBO是问题仍然存在,但是如果您仍然想在更改数据类型
1. protivilages 之后使用检查这些东西。
2.反转控制
3. Auto调谐
Datatype is String use INT
And the simplest solution is do not use CBO is problem still remains but if you still want to use check these things after altering the datatype
1.Privilages
2.Version control
3.auto tuned
在查询中使用多个项目
从示例中选择fname,其中sid in('11',''22');
Use in query to select multiple item
select fname from sample where sid in ('11','22');