zzwqqq created CALCITE-7914:
-------------------------------
Summary: RelDecorrelator produces wrong results for
non-deterministic inputs
Key: CALCITE-7914
URL: https://issues.apache.org/jira/browse/CALCITE-7914
Project: Calcite
Issue Type: Bug
Reporter: zzwqqq
Assignee: zzwqqq
{{RelDecorrelator}} may evaluate the outer input again to build distinct
correlation values, then join the subquery results back by those values. With
{{{}RAND(){}}}, the two branches can produce different keys, so the subquery
result may fail to match the original outer row.
In the query below, {{RAND()}} is always less than 1, so the subquery should
count its single row.
Example:
{code:sql}
select (select count(*) from (values 1) s(x) where t.r < s.x) as p
from (select rand() as r) t;
{code}
Expected:
{code:java}
+---+
| P |
+---+
| 1 |
+---+
(1 row)
{code}
Actual:
{code:java}
+---+
| P |
+---+
| 0 |
+---+
(1 row)
{code}
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)