【问题标题】:Does Hive Optimizer consider view definition while optimizing queries on views?Hive Optimizer 在优化视图查询时是否考虑视图定义?
【发布时间】:2017-07-06 07:40:42
【问题描述】:

我有这个架构(通过 DDL 为表和视图提供):

hive> create table t_realtime(cust_id int, name string, status string, active_flag int);

hive> create table t_hdfs(cust_id int, name string, status string, active_flag int);

hive> create view t_inactive as select * from t_hdfs where active_flag=0;

hive> create view t_view as select * from t_realtime union all select * from t_inactive;

如果我触发如下查询:

hive> select * from t_view where active_flag = 1;

理想情况下,此查询不应访问 t_inactive 视图或 t_hdfs,因为 t_inactive 的视图定义本身具有 active_flag = 0 并且查询谓词具有 active_flag = 1。但是,默认情况下,它不会消除此联合视图的 t_inactive 部分。

对于这样的蜂巢查询,有没有办法实现这一点?也许是一些配置单元优化器参数或提示?

【问题讨论】:

  • 根据您的决定,“默认情况下,它不会消除此联合视图的 t_inactive 部分。”

标签: sql hadoop hive query-optimization


【解决方案1】:
hive> explain extended select * from t_view where active_flag = 1;
OK
STAGE DEPENDENCIES:
  Stage-0 is a root stage

STAGE PLANS:
  Stage: Stage-0
    Fetch Operator
      limit: -1
      Processor Tree:
        TableScan
          alias: t_realtime
          properties:
            insideView TRUE
          GatherStats: false
          Filter Operator
            isSamplingPred: false
            predicate: (active_flag = 1) (type: boolean)
            Select Operator
              expressions: cust_id (type: int), name (type: string), status (type: string), 1 (type: int)
              outputColumnNames: _col0, _col1, _col2, _col3
              ListSink

这是在昨天的主线(d68630b6ed25884a76030a9073cd864032ab85c2)上测试的。如您所见,它只扫描t_realtime 并下推谓词active_flag = 1您的 特定安装是否会执行此操作,这取决于您使用的版本。该主题正在积极开发中,不仅在 Hive 上,而且在 Calcite(由 Hive 使用)上。

【讨论】:

  • 非常感谢!!
  • 您能否提及您尝试过的 Hive 版本?您是否建议它在最新的 Hive 版本分支中进行工作?
猜你喜欢
  • 2019-08-23
  • 2021-09-13
  • 1970-01-01
  • 2021-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多