You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hive.apache.org by "Stamatis Zampetakis (Jira)" <ji...@apache.org> on 2025/06/27 08:02:00 UTC

[jira] [Resolved] (HIVE-28910) Remove redundant IS NOT NULL predicates when expanding SEARCH

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

Stamatis Zampetakis resolved HIVE-28910.
----------------------------------------
    Fix Version/s: 4.2.0
       Resolution: Fixed

Fixed in https://github.com/apache/hive/commit/925df927248c1be11b84df3e8a0c3e43955e133e

> Remove redundant IS NOT NULL predicates when expanding SEARCH
> -------------------------------------------------------------
>
>                 Key: HIVE-28910
>                 URL: https://issues.apache.org/jira/browse/HIVE-28910
>             Project: Hive
>          Issue Type: Improvement
>          Components: CBO
>            Reporter: Stamatis Zampetakis
>            Assignee: Stamatis Zampetakis
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 4.2.0
>
>
> During various CBO transformations (especially during simplifications) the internal SEARCH (CALCITE-4173) operator is introduced in the plan. The SEARCH operator cannot be executed directly and must be expanded (using SearchTransformer) to an equivalent form for further processing.
> Currently the expansion is conservative and does not take into account the context for the evaluation of UNKNOWN/NULL values which in some cases can lead to redundant IS [NOT] NULL predicates in the expanded form.
> +Example+
> {code:sql}
> explain cbo
> select d_date_sk
> from date_dim
> where d_dom IN (1, 2, 3)
>   and d_dom IS NOT NULL
> {code}
> The intermediate plan before SEARCH expansion is shown below:
> {noformat}
> HiveProject(d_date_sk=[$0])
>   HiveFilter(condition=[SEARCH($9, Sarg[1, 2, 3; NULL AS FALSE])])
>     HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
> {noformat}
> The final plan  after SEARCH expansion is show below:
> {noformat}
> HiveProject(d_date_sk=[$0])
>   HiveFilter(condition=[AND(IN($9, 1, 2, 3), IS NOT NULL($9))])
>     HiveTableScan(table=[[default, date_dim]], table:alias=[date_dim])
> {noformat}
> Observe that the IS NOT NULL predicate is redundant both in the SQL query and in the plan however the optimizer is not able to remove it. 
> The IS NOT NULL predicate is introduced cause the Sarg indicates that we should handle NULL AS FALSE. However, inside a Filter operator (WHERE clause) nulls are always treated as false so we can skip the addition of the predicate.



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