[
https://issues.apache.org/jira/browse/IMPALA-7737?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Tim Armstrong updated IMPALA-7737:
----------------------------------
Component/s: Frontend
Backend
> 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
> Components: Backend, Frontend
> Affects Versions: Impala 3.0
> Reporter: Paul Rogers
> Priority: Major
>
> 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
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]