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

Julian Hyde commented on CALCITE-5703:
--------------------------------------

In the current PR I'm not seeing much reduction in code volume (just a few null 
casts removed). If there are significant changes in code generation I'd like to 
see these evidenced in tests.

I totally agree with the goal. I think the code we generate is much too 
verbose. However, there is good reason for the current state of the code. For 
example, consider common subexpression elimination in the following expression:
{code:sql}
case
when x < 10 then y + 1
when x is null then 0
when x < 20 or (y + 1) > 100 then 2
else 5 - (y + 1)
end 
{code}
After the 2nd branch, and in the 'then' of the first branch, we know that x is 
not null, and therefore we should skip the 'is null' check. The subexpression 
'y + 1' is used in three different places, but each place cannot guarantee that 
the previous occurrence has been executed.

> Reduce amount of generated runtime code
> ---------------------------------------
>
>                 Key: CALCITE-5703
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5703
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>    Affects Versions: 1.34.0
>            Reporter: Evgeny Stanilovsky
>            Assignee: Evgeny Stanilovsky
>            Priority: Major
>              Labels: patch-available
>
> In some cases runtime generates code like :
> {noformat}
> return case_when_value == null ? (String) null : some_oparation();
> or
> return input_value == null ? (Long) null : Long.valueOf(...;
> {noformat}
> this redundant casting probably not harmful, but there is another side - 
> maximum method size, this size jdk[1], janino [2] throws : *Code grows beyond 
> 64 KB* . This PR reduces code generated by calcite runtime thus more huge 
> expressions can be executed.
> [1] 
> https://github.com/openjdk/jdk/blob/d22bcc813eea719b817d3d541a843594675c0ca9/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassFile.java#L101
> [2] 
> https://github.com/janino-compiler/janino/blob/e69022f5aaabd36edc08a2074360d62514493a19/janino/src/main/java/org/codehaus/janino/CodeContext.java#L699



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

Reply via email to