You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "Zoltan Haindrich (JIRA)" <ji...@apache.org> on 2018/05/10 11:22:00 UTC

[jira] [Commented] (HIVE-19097) related equals and in operators may cause inaccurate stats estimations

    [ https://issues.apache.org/jira/browse/HIVE-19097?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16470235#comment-16470235 ] 

Zoltan Haindrich commented on HIVE-19097:
-----------------------------------------

I've re-checked the current state of this fix:
 * for branch-2
 ** I would recommend to stay with the "localReferencedColumns" approach what I've started in patch 01 (without that small refactor)
 * for branch-3/master
 ** CALCITE-2247 could enable the simplification of (a=1 7& (a=2 || a=1)) to (a=1)
 ** but since Calcite is *always* breaking up "IN" clauses during sql parsing;
   Hive would need a facility to do that; I would like to suggest to add an IN opener to {{HivePointLookupOptimizerRule}}; since that rule already has an IN closer which closes large ORs.
[link to my current wip tree|https://github.com/apache/hive/compare/master...kgyrtkirk:HIVE-19097-related-equals#diff-85205e52a019624957e9ce940ff7cbeeR145] to add the in opener to hive

[~jcamachorodriguez], [~ashutoshc]: what do you think about the above?

> related equals and in operators may cause inaccurate stats estimations
> ----------------------------------------------------------------------
>
>                 Key: HIVE-19097
>                 URL: https://issues.apache.org/jira/browse/HIVE-19097
>             Project: Hive
>          Issue Type: Bug
>            Reporter: Zoltan Haindrich
>            Assignee: Zoltan Haindrich
>            Priority: Major
>         Attachments: HIVE-19097.01.patch, HIVE-19097.partial.patch
>
>
> tpcds#74 is optimized in a way that for date_dim the condition contains IN and = for the same column
> {code:java}
> |             Map Operator Tree:                     |
> |                 TableScan                          |
> |                   alias: date_dim                  |
> |                   filterExpr: (((d_year) IN (2001, 2002) and (d_year = 2002) and d_date_sk is not null) or ((d_year) IN (2001, 2002) and (d_year = 2001) and d_date_sk is not null)) (type: boolean) |
> |                   Statistics: Num rows: 73049 Data size: 876588 Basic stats: COMPLETE Column stats: COMPLETE |
> |                   Filter Operator                  |
> |                     predicate: ((d_year) IN (2001, 2002) and (d_year = 2002) and d_date_sk is not null) (type: boolean) |
> |                     Statistics: Num rows: 4 Data size: 48 Basic stats: COMPLETE Column stats: COMPLETE |
> {code}
> the "real" row count will be 365
> for separate {{IN}} and {{=}} the estimation is very good; but if both are present it becomes (very) underestimated.
> {code:java}
> set hive.query.results.cache.enabled=false;
> drop table if exists t1;
> drop table if exists t8;
> create table t1 (a integer,b integer);
> create table t8 like t1;
> insert into t1 values (1,1),(2,2),(3,3),(4,4),(5,5);
> insert into t8
> select * from t1 union all select * from t1 union all select * from t1 union all select * from t1 union all
> select * from t1 union all select * from t1 union all select * from t1 union all select * from t1
> ;
> analyze table t1 compute statistics for columns;
> analyze table t8 compute statistics for columns;
> explain analyze select sum(a) from t8 where b in (2,3) group by b;
> explain analyze select sum(a) from t8 where b=2 group by b;
> explain analyze select sum(a) from t1 where b in (2,3) and b=2 group by b;
> explain analyze select sum(a) from t8 where b in (2,3) and b=2 group by b;
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)