Skip to content

Optimize LEFT JOIN with constant false ON clause condition #919

@mbasmanova

Description

@mbasmanova

When a LEFT JOIN ON clause contains a constant false conjunct (e.g., ON a = x AND 1 > 2), the optimizer currently keeps it as a filter: false on the JoinEdge.
This means the join executes but never matches any rows.

The optimal plan would eliminate the join entirely and produce left rows with NULL right columns, since a false filter guarantees no right row can ever match.

Current behavior

SELECT * FROM t LEFT JOIN u ON a = x AND 1 > 2

Plan:

HashJoin[LEFT a=x, filter: false]
  TableScan[t]
  TableScan[u]

Expected behavior

The join should be eliminated. The plan should scan only t and project NULLs for the right-side columns:

Project[a, b, c, null AS x, null AS y]
  TableScan[t]

Test coverage

A test case exists in JoinTest.leftJoinOnClausePushdown that documents the current behavior and references this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions