为什么选择Count(*)比hive中的Select*慢

Har*_*ris 18 sql hadoop hive

当我在VirtualBox Sandboxhive中运行查询时.我觉得Select count(*)比这慢得多Select *.

谁能解释一下后面发生了什么?

为什么会出现这种延迟?

Mas*_*ask 12

select * from table
Run Code Online (Sandbox Code Playgroud)

它可以是Map only工作但是

Select Count(*) from table 
Run Code Online (Sandbox Code Playgroud)

它可以是Map和Reduce工作

希望这可以帮助.


Ale*_*ec. 3

这是因为数据库使用聚集主键,因此查询会逐行逐行搜索该键,而不是从索引中搜索。

  • 跑步optimize table。这将确保数据页按排序顺序物理存储。可以想象,这可以加快集群主键上的范围扫描速度。

  • 仅在change_event_id 列上创建额外的非主索引。这将在索引页中存储该列的副本,扫描速度要快得多。创建后,检查解释计划以确保它使用新索引