You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "zzwqqq (Jira)" <ji...@apache.org> on 2026/10/23 09:13:00 UTC

[jira] [Created] (CALCITE-7885) RelDecorrelator merges distinct correlation fields and produces extra rows

zzwqqq created CALCITE-7885:
-------------------------------

             Summary: RelDecorrelator merges distinct correlation fields and produces extra rows
                 Key: CALCITE-7885
                 URL: https://issues.apache.org/jira/browse/CALCITE-7885
             Project: Calcite
          Issue Type: Bug
          Components: core
            Reporter: zzwqqq
            Assignee: zzwqqq


{{rewriteScalarAggregate}} uses aggregate column positions as keys in {{{}newProjectMap{}}}. Different outer references can share a position, so one overwrites another. When their values differ on unmatched rows, the final join can attach an aggregate result to the wrong outer row. 
For example: 
{code:sql}
with t(x, y) as (values (1, 1), (2, 1)),
     s(z) as (values (1))
select t.x, t.y,
  (select count(*) from s where s.z = t.x and s.z = t.y) as c
from t;
{code}
Expected:
{code:sql}
+---+---+---+
| X | Y | C |
+---+---+---+
| 1 | 1 | 1 |
| 2 | 1 | 0 |
+---+---+---+
(2 rows)
{code}
Actual:
{code:sql}
+---+---+---+
| X | Y | C |
+---+---+---+
| 1 | 1 | 1 |
| 2 | 1 | 0 |
| 1 | 1 | 0 |
+---+---+---+
(3 rows)
{code}



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)