配置单元优化器在优化视图查询时是否考虑视图定义?

zbsbpyhn  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(356)

我有这个模式(通过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 并且查询 predicate active_flag = 1 . 但是,默认情况下,它不会消除 t_inactive 这是工会观点的一部分。
对于这样的配置单元查询,是否还有其他方法可以实现这一点?可能是一些配置单元优化器参数或提示?

afdcj2ne

afdcj2ne1#

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 并向下推 predicate active_flag = 1 . 无论您的特定安装是否会这样做,这取决于您使用的版本。这个主题是积极发展,不仅在Hive,而且方解石(Hive使用)。

相关问题