Yaoxuan Wu created FLINK-41749:
----------------------------------

             Summary: Streaming multi-way join drops a filter on the join-key 
column of a join input (wrong result with table.optimizer.multi-join.enabled)
                 Key: FLINK-41749
                 URL: https://issues.apache.org/jira/browse/FLINK-41749
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Planner
    Affects Versions: 2.3.0
            Reporter: Yaoxuan Wu


With table.optimizer.multi-join.enabled = true, a join of two sub-plans that 
are joins, one
filtered by a predicate on the column that is the outer join key, returns rows 
the filter
excludes.

{code:sql}
SET 'execution.runtime-mode' = 'streaming';
SET 'table.optimizer.multi-join.enabled' = 'true';
CREATE TEMPORARY VIEW t AS SELECT * FROM (VALUES (1, TRUE, FALSE), (2, FALSE, 
TRUE)) AS v(k, h, b);
CREATE TEMPORARY VIEW j AS SELECT t.h, t.b FROM t JOIN (SELECT DISTINCT k FROM 
t) u ON t.k = u.k;
SELECT x.h, y.b FROM j AS x JOIN (SELECT * FROM j WHERE b) AS y ON x.h = y.b;
{code}

Expected (and returned with multi-join disabled): (TRUE, TRUE).
Actual: (FALSE, FALSE), (TRUE, TRUE) -- y.b = FALSE passed WHERE b.

The optimized physical plan shows the right input of the outer MultiJoin as
Calc(select=[h]) over MultiJoin(... Calc(select=[k, h]) ...), identical to the 
left input:
the filter `b` and the column `b` are gone. With multi-join disabled that side 
is
Calc(select=[..., b], where=[b]). In a larger query the filter survived but on 
the wrong
column (where=[h] instead of where=[b]).

Also wrong: the filter on the other column (`WHERE h` with x.b = y.h) and a 
right input
that differs structurally from the left one. Correct: WHERE b IS NOT NULL, an 
INT key with
WHERE a = -2, or inputs that are not joins. Sub-plan reuse is not involved 
(same result with
table.optimizer.reuse-sub-plan-enabled = false). Reproduces on 2.2.0, 2.3.0 and 
a master
snapshot of 2026-11-19 (2.0 has no multi-join). A PyFlink script is attached.




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

Reply via email to