HIVE select count(*)non null返回高于select count(*)的值

时间:2016-10-07 08:27:20

标签: hive hiveql

我目前正在使用Hive进行一些数据探索,无法解释以下行为。假设我有一个带有字段master_id的表(名为mytable)。

当我计算我得到的行数时

select count(*) as c from mytable 
c
1129563

如果我想用非null master_id计算行数,我得到一个更高的数字

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

此外,master_id似乎永远不会为空。

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

我无法解释添加where语句最终会如何增加行数。有没有人有任何提示来解释这种行为?

由于

1 个答案:

答案 0 :(得分:5)

很可能你的查询没有使用统计信息,因为设置了这个参数:

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

尝试将其设置为false并再次执行。

或者,您可以计算表格的统计数据。 见ANALYZE TABLE SYNTAX

此外,还可以自动在INSERT OVERWRITE期间收集统计信息:

set hive.stats.autogather=true;