Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CH] Duplicated expression evaluation in project before aggregate operator due to PullOutPreProject Rule #8183

Open
taiyang-li opened this issue Dec 9, 2024 · 1 comment
Labels
bug Something isn't working triage

Comments

@taiyang-li
Copy link
Contributor

taiyang-li commented Dec 9, 2024

Backend

CH (ClickHouse)

Bug description

In below query, expr if(id % 2 = 0, id+3, id+4) was evaluated twice both in n3 and _pre_5. I find that _pre_5 is introduced by PullOutPreProject in #4213. cc @PHILO-HE @zhztheplayer can you find similar issue in Velox?

explain extended 
select max(n1), max(n2), sum(if(n1+n2+n3 % 2 = 0, 1, 0)) from (select id+1 as n1, id+2 as n2, if(id % 2 = 0, id+3, id+4) as n3 from range(10)) 
== Optimized Logical Plan ==
Aggregate [max(n1#375L) AS max(n1)#386L, max(n2#376L) AS max(n2)#387L, sum(if ((((n1#375L + n2#376L) + (n3#377L % 2)) = 0)) 1 else 0) AS sum((IF((((n1 + n2) + (n3 % 2)) = 0), 1, 0)))#389L]
+- Project [(id#383L + 1) AS n1#375L, (id#383L + 2) AS n2#376L, if (((id#383L % 2) = 0)) (id#383L + 3) else (id#383L + 4) AS n3#377L]
   +- Range (0, 10, step=1, splits=None)

== Physical Plan ==
CHNativeColumnarToRow
+- ^(9) HashAggregateTransformer(keys=[], functions=[max(n1#375L), max(n2#376L), sum(_pre_5#396)], isStreamingAgg=false, output=[max(n1)#386L, max(n2)#387L, sum((IF((((n1 + n2) + (n3 % 2)) = 0), 1, 0)))#389L])
   +- ^(9) ProjectExecTransformer [(id#383L + 1) AS n1#375L, (id#383L + 2) AS n2#376L, if (((id#383L % 2) = 0)) (id#383L + 3) else (id#383L + 4) AS n3#377L, if (((((id#383L + 1) + (id#383L + 2)) + (if (((id#383L % 2) = 0)) (id#383L + 3) else (id#383L + 4) % 2)) = 0)) 1 else 0 AS _pre_5#396]
      +- ^(9) InputIteratorTransformer[id#383L]
         +- RowToCHNativeColumnar
            +- *(1) Range (0, 10, step=1, splits=1)

Spark version

None

Spark configurations

No response

System information

No response

Relevant logs

No response

@taiyang-li taiyang-li added bug Something isn't working triage labels Dec 9, 2024
@taiyang-li taiyang-li changed the title [CH] Duplicated expression evaluation caused by PullOutPreProject Rule [CH] Duplicated expression evaluation in project before aggregate operator caused by PullOutPreProject Rule Dec 9, 2024
@taiyang-li taiyang-li changed the title [CH] Duplicated expression evaluation in project before aggregate operator caused by PullOutPreProject Rule [CH] Duplicated expression evaluation in project before aggregate operator due to PullOutPreProject Rule Dec 9, 2024
@PHILO-HE
Copy link
Contributor

@taiyang-li, just tested Velox backend. It has the same issue.

(5) ProjectExecTransformer
Output [4]: [(id#3036L + cast(1 as bigint)) AS n1#3033L, (id#3036L + cast(2 as bigint)) AS n2#3034L, if (((id#3036L % cast(2 as bigint)) = cast(0 as bigint))) (id#3036L + cast(3 as bigint)) else (id#3036L + cast(4 as bigint)) AS n3#3035L, if (((((id#3036L + cast(1 as bigint)) + (id#3036L + cast(2 as bigint))) + (if (((id#3036L % cast(2 as bigint)) = cast(0 as bigint))) (id#3036L + cast(3 as bigint)) else (id#3036L + cast(4 as bigint)) % cast(2 as bigint))) = cast(0 as bigint))) 1 else 0 AS _pre_0#3065]
Input [1]: [id#3036L]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage
Projects
None yet
Development

No branches or pull requests

2 participants