【问题标题】:Performance of Join vs Subquery in Where Clause (HIVE)Where 子句 (HIVE) 中连接与子查询的性能
【发布时间】:2019-03-19 06:26:53
【问题描述】:

有人可以帮我了解哪种方法最有效。

第一个表 users_of_interest_table 有一列 users 有大约 1,000 个唯一用户 ID。

第二个表app_logs_table 有一个users 列和一个app_log 列。该表有超过 10 亿行和超过 1000 万的唯一用户。

users_of_interest 中的用户获取所有应用日志数据的最有效方法是什么。到目前为止,这是我想出的。

选项 1:使用内部联接

SELECT 
  u.users, a.app_logs
FROM 
  users_of_interest_table u
INNER JOIN 
  app_logs_table a
ON 
  u.users = a.users

选项 2:Where 子句中的子查询

SELECT 
  a.users, a.app_logs
FROM 
  app_logs_table a
WHERE 
  a.users IN (SELECT u.users FROM users_of_interest_table u)

【问题讨论】:

  • 您的用户表的大小是多少?它只包含 Ids 吗?
  • users_of_interest 表只包含 Ids 并且有 1000 行。

标签: hive inner-join where


【解决方案1】:

社区建议使用 Join 子句,但是,在我所做的一些测试中,In 子句效率更高

您必须自己进行测试,为此使用 SQL Server Profile 工具

【讨论】:

    猜你喜欢
    • 2015-03-29
    • 2014-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多