[ 
https://issues.apache.org/jira/browse/HIVE-29424?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Thomas Rebele updated HIVE-29424:
---------------------------------
    Description: 
Similar to HIVE-29364: the CBO planner should use the histogram statistics to 
estimate the selectivity of predicates such as
 * {{cast(b as BIGINT) < 6}}
 * {{cast(g as timestamp) >= "2020-11-7 00:00:00"}}
 * {{cast(g as timestamp) BETWEEN "2020-11-01 00:00:00" AND "2020-11-06 
00:00:00"}}

The hint of HIVE-29364 should be taken into account: if the CAST throws away 
information, the histogram statistics should not be used. E.g., {{{}CAST(128 as 
TINYINT) = -128{}}}, so a {{CAST(intField as TINYINT) > 42}} should not be 
treated the same as {{{}intField > 42{}}}, if the intField is outside of the 
range of TINYINT.

This change would allow Hive to use the histogram statistics for many TPC-DS 
queries, e.g., query 82 contains a {{{}d_date between cast('2002-05-30' as 
date) and (cast('2002-05-30' as date) +  60 days){}}}, which will be implicitly 
converted to a RexNode {{{}BETWEEN(false, CAST($2):TIMESTAMP(9), 2002-05-30 
00:00:00:TIMESTAMP(9), 2002-07-29 00:00:00:TIMESTAMP(9)){}}}.

  was:
Similar to HIVE-29364: the CBO planner should use the histogram statistics to 
estimate the selectivity of predicates such as
 * {{cast(b as BIGINT) < 6}}
 * {{cast(g as timestamp) >= "2020-11-7 00:00:00"}}
 * {{cast(g as timestamp) BETWEEN "2020-11-01 00:00:00" AND "2020-11-06 
00:00:00"}}

The hint of HIVE-29364 should be taken into account: if the CAST throws away 
information, the histogram statistics should not be used. E.g., {{{}CAST(128 as 
TINYINT) = -128{}}}, so a {{CAST(intField as TINYINT) > 42}} should not be 
treated the same as {{{}intField > 42{}}}, if the intField is outside of the 
range of TINYINT.


> CBO plans should use histogram statistics for range predicates with a CAST
> --------------------------------------------------------------------------
>
>                 Key: HIVE-29424
>                 URL: https://issues.apache.org/jira/browse/HIVE-29424
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Thomas Rebele
>            Assignee: Thomas Rebele
>            Priority: Major
>              Labels: pull-request-available
>
> Similar to HIVE-29364: the CBO planner should use the histogram statistics to 
> estimate the selectivity of predicates such as
>  * {{cast(b as BIGINT) < 6}}
>  * {{cast(g as timestamp) >= "2020-11-7 00:00:00"}}
>  * {{cast(g as timestamp) BETWEEN "2020-11-01 00:00:00" AND "2020-11-06 
> 00:00:00"}}
> The hint of HIVE-29364 should be taken into account: if the CAST throws away 
> information, the histogram statistics should not be used. E.g., {{{}CAST(128 
> as TINYINT) = -128{}}}, so a {{CAST(intField as TINYINT) > 42}} should not be 
> treated the same as {{{}intField > 42{}}}, if the intField is outside of the 
> range of TINYINT.
> This change would allow Hive to use the histogram statistics for many TPC-DS 
> queries, e.g., query 82 contains a {{{}d_date between cast('2002-05-30' as 
> date) and (cast('2002-05-30' as date) +  60 days){}}}, which will be 
> implicitly converted to a RexNode {{{}BETWEEN(false, CAST($2):TIMESTAMP(9), 
> 2002-05-30 00:00:00:TIMESTAMP(9), 2002-07-29 00:00:00:TIMESTAMP(9)){}}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to