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/22 18:55:00 UTC

[jira] [Created] (IMPALA-7737) Extend CASE code generation to cache repeated sub-expressions

Paul Rogers created IMPALA-7737:
-----------------------------------

             Summary: Extend CASE code generation to cache repeated sub-expressions
                 Key: IMPALA-7737
                 URL: https://issues.apache.org/jira/browse/IMPALA-7737
             Project: IMPALA
          Issue Type: Improvement
    Affects Versions: Impala 3.0
            Reporter: Paul Rogers


IMPALA-7655 suggests rewriting several conditional functions which can result in repeated evaluation of the same sub-expression. For example:

{code:sql}
ISNULL(expr, ifNull)
{code}

Might become:

{code:sql}
CASE WHEN expr IS NULL THEN ifNull ELSE expr END
{code}

In the original (interpreted) form, {{expr}} is evaluated once but used twice. In the code generated form for {{CASE}}, {{expr}} will be evaluated twice, removing some of the benefit of the rewrite.

This ticket requests to modify the FE and BE to handle common subexpressions.

In the most general case, the FE would search for such common subexpressions. For our purposes, a more narrow approach is possible: the rewrite rule would simply label such expressions during the rewrite.

Note that the label must survive subsequent rewrites (or such rewrites must be done before the rewrite into CASE.) For example:

{code:sql}
ISNULL(1 + 2 + 3 + col, 5)
{code}

Will be rewritten to:

{code:sql}
ISULL(6 + col, 6)
{code}

Ideally, the above rewrite would be done before the {{ISNULL}} rewrite so we'd not lose our tag. Then, we can tag the rewritten case EXPR (making something up):

{code:sql}
CASE WHEN 6 + col {tag: $1} IS NULL THEN ifNull ELSE $1 END
{code}

Or:
{code:sql}
TAGS $1: 6 + col CASE WHEN $1 IS NULL THEN ifNull ELSE $1 END
{code}

The code generation for CASE in the BE would be aware of these tags and would:

* In the same block where the {{CASE expr ...}} is evaluated, evaluate and store any tagged expressions.
* When performing the {{WHEN}}, {{THEN}} and {{ELSE}} clauses, modify code gen to refer back to prior saved values.



--
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