FangHao created FLINK-40753:
-------------------------------

             Summary: Correlated subqueries over SQL VALUES fail during 
decorrelation
                 Key: FLINK-40753
                 URL: https://issues.apache.org/jira/browse/FLINK-40753
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Planner
    Affects Versions: 2.4.0
         Environment: Flink 2.4-SNAPSHOT, upstream master at 43c220f6dc3.
Java 21 on macOS.
Reproduced in both batch and streaming modes using 
TableEnvironment.explainSql().
            Reporter: FangHao


Correlated EXISTS / NOT EXISTS subqueries over SQL VALUES fail during planning 
in both batch and streaming modes. This is reproducible through the Java 
TableEnvironment without the Python DataFrame API, on upstream master at 
43c220f6dc3.

Reproducer:
{code:sql}
SELECT l.id
FROM (VALUES (1), (2)) AS l(id)
WHERE NOT EXISTS (
    SELECT 1
    FROM (VALUES (1), (2)) AS r(right_id)
    WHERE l.id = r.right_id
);
{code}

Expected: the query plans successfully and returns no rows.

Actual:
{code}
org.apache.flink.table.api.TableException:
unexpected correlate variable $cor0 in the plan
{code}

SubQueryDecorrelator.decorrelateRel(Values) returns a null Frame, which signals 
that decorrelation cannot continue. A Values node does not require 
modification, but it should return an identity Frame so its parent 
filter/project can still be decorrelated.

Once this path is enabled, project decorrelation must also handle 
RelOptUtil.createProject simplifying a projection to Values, rather than 
assuming the result is always a LogicalProject.

A fix has been validated locally with batch/streaming plan tests and batch 
execution tests covering NULL keys, duplicate rows, empty inputs, projections, 
filters, and computed keys.

Discovered while implementing FLINK-40419. Reviewer discussion:
https://github.com/apache/flink/pull/29201#discussion_r4068948306

I would like to work on this fix. Could a committer assign this issue to me?



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

Reply via email to