hive select count(*)非空返回的值高于select count(*)

mnemlml8  于 2021-06-28  发布在  Hive
关注(0)|答案(1)|浏览(599)

我目前正在使用hive进行一些数据探索,无法解释以下行为。假设我有一个表(名为mytable)和一个字段主id。
当我数我得到的行数

select count(*) as c from mytable 
c
1129563

如果我想计算具有非空主\标识的行数,我会得到一个更高的数字

select count(*) as c from mytable where master_id is not null
c
1134041

此外,master\u id似乎从不为空。

select count(*) as c from mytable where master_id is null
c
0

我无法解释添加where语句最终如何增加行数。有人有什么线索来解释这种行为吗?
谢谢

hfwmuf9z

hfwmuf9z1#

最可能的情况是,由于设置了以下参数,您的查询(不带where)正在使用统计信息:

set hive.compute.query.using.stats=true;

尝试将其设置为false并再次执行。
或者,您可以计算表上的统计信息。请参见分析表语法
此外,还可以在插入覆盖期间自动收集统计信息:

set hive.stats.autogather=true;

相关问题