You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues-all@impala.apache.org by "Paul Rogers (JIRA)" <ji...@apache.org> on 2018/10/24 23:32:00 UTC

[jira] [Commented] (IMPALA-7750) Additional FE optimizations for CASE expressions

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

Paul Rogers commented on IMPALA-7750:
-------------------------------------

Some of the limitations described here may actually be due to limitations of the test framework rather than of the product.

In unit test path, each simplification rule is applied once. The constant-folding rule is applied before the if-rewrite. Thus, if we generate null is null, the constant folding rule won't be applied a second time. Instead, the {{ifnull()}} rewrite code must handle these optimizations.

Oddly, outside of the rule rewrite unit tests, rules are applied repeatedly, and so the upstream rewrites might be done. This seems a limitation in the testing framework.

So, perhaps we need a version of the rewrite tests that will apply a set of rules multiple times to better simulate a production setup.

> Additional FE optimizations for CASE expressions
> ------------------------------------------------
>
>                 Key: IMPALA-7750
>                 URL: https://issues.apache.org/jira/browse/IMPALA-7750
>             Project: IMPALA
>          Issue Type: Improvement
>          Components: Frontend
>    Affects Versions: Impala 3.0
>            Reporter: Paul Rogers
>            Priority: Major
>
> The current FE {{CASE}} rewrite code in {{SimplifyConditionalsRule.simplifyCaseExpr()}} misses some opportunities for optimizations. If these rules are implemented, then the ad-hoc rules for several other functions can be removed.
> h4. Constant Folding
> Consider a typical un-optimized conditional function rewrite:
> {code:sql}
> CASE WHEN NULL IS NULL THEN 10 ELSE 20 END
> {code}
> Should be rewritten to just {{10}} since the expression is always true. (Currently the expression is not rewritten.)
> The same issue occurs for the inverse:
> {code:sql}
> CASE WHEN 10 IS NULL THEN 10 ELSE 20 END
> {code}
> Fix these and we can remove the ad-hoc rules for {{NULLIF}} and aliases in {{rewriteNullIfFn()}}. Also {{nvl2()}} in {{rewriteNvl2Fn}} and {{ifnull()}} in {{rewriteIfNullFn()}}.
> In general, any constant expression should be evaluated:
> {code:sql}
> CASE WHEN isTrue(TRUE) THEN 10 ELSE 20 END
> {code}
> The constant expression can be evaluated and optimized as for constants. Tests suggest that the {{ConstantFoldingRule}} does not handle these cases.
> h4. Prune Trivial ELSE Clause
> A trivial optimization is to omit ELSE if it adds no value:
> {code:sql}
> CASE WHEN id = 10 THEN id ELSE NULL END
> {code}
> The {{ELSE}} case defaults to null if not provided, so the above can be rewritten to:
> {code:sql}
> CASE WHEN id = 10 THEN id END
> {code}



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

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-all-unsubscribe@impala.apache.org
For additional commands, e-mail: issues-all-help@impala.apache.org