Github user comnetwork commented on a diff in the pull request: https://github.com/apache/phoenix/pull/314#discussion_r206012706 --- Diff: phoenix-core/src/main/java/org/apache/phoenix/expression/Expression.java --- @@ -88,4 +88,10 @@ * @return */ boolean requiresFinalEvaluation(); + + /** + * + * @return + */ + boolean isConstantIfChildrenAllConstant(); --- End diff -- I think ExpressionUtil.isConstant(Expression) is not suitable for this case, just as the comments of jira said, what we want to check in this issue is if a expression is constant when all children of it are constants, just consider following sql: select a.ak3 from (select rand() ak1,length(pk2) ak2,length(pk3) ak3,length(v1) av1,length(v2) av2 from test order by pk2,pk3 limit 10) a where a.ak1 = 0.0 and a.av2 = length(substr('abc',1,1)) group by a.ak3,CASE WHEN coalesce(a.ak1,1) > coalesce(a.av2,2) THEN coalesce(a.ak1,1) ELSE coalesce(a.av2,2) END,a.av1 order by a.ak3,a.av1 Obviously , because of rand(), the Determinism of expression a.ak1 is Determinism.PER_INVOCATION, so the determinism is Determinism.PER_INVOCATION and isStateless is false for expression "CASE WHEN coalesce(a.ak1,1) > coalesce(a.av2,2) THEN coalesce(a.ak1,1) ELSE coalesce(a.av2,2) END", but because the a.ak1 and a.av2 are both constants in where clause of outer query, we can regard "CASE WHEN coalesce(a.ak1,1) > coalesce(a.av2,2) THEN coalesce(a.ak1,1) ELSE coalesce(a.av2,2) END" as constant in IsConstantVisitor.
---