Skip to content

Fix wrong results for WHERE on inherited column with LEFT JOIN ON FALSE#8591

Open
colm-mchugh wants to merge 1 commit into
mainfrom
feature/inheritance-left-join-fix
Open

Fix wrong results for WHERE on inherited column with LEFT JOIN ON FALSE#8591
colm-mchugh wants to merge 1 commit into
mainfrom
feature/inheritance-left-join-fix

Conversation

@colm-mchugh
Copy link
Copy Markdown
Contributor

DESCRIPTION: Fix wrong results for WHERE on inheritance parent column with LEFT JOIN ON FALSE

Problem: When a local inheritance parent table is cross-joined with a distributed table through LEFT JOIN ... ON FALSE, PostgreSQL's expand_single_inheritance_child() creates child RTEs via memcpy, duplicating Citus's identity marker (values_lists). This causes RelationRestrictionForRelation() to return the child's restriction instead of the parent's. Since Vars in plannerInfo->parse still reference the parent's original rtable position, RequiredAttrNumbersForRelationInternal() finds no matching Vars, causing all columns to be replaced with NULL, and ultimately producing wrong (empty) query results.

Fix: Add an originalRteIndex parameter to RequiredAttrNumbersForRelation() that also searches at the RTE's original position in the query's rtable when it differs from the restriction's index. Fixes: #8553

@colm-mchugh colm-mchugh self-assigned this May 20, 2026
@colm-mchugh colm-mchugh force-pushed the feature/inheritance-left-join-fix branch from 575fb64 to 100255d Compare May 20, 2026 09:10
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.76%. Comparing base (c2bd6ae) to head (d06e2c0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8591   +/-   ##
=======================================
  Coverage   88.75%   88.76%           
=======================================
  Files         288      288           
  Lines       64263    64272    +9     
  Branches     8086     8086           
=======================================
+ Hits        57036    57050   +14     
+ Misses       4892     4885    -7     
- Partials     2335     2337    +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…IN ON FALSE

When a local inheritance parent table is cross-joined with a distributed
table through LEFT JOIN ... ON FALSE, PostgreSQL's expand_single_inheritance_child()
creates child RTEs via memcpy, duplicating Citus's identity marker (values_lists).
This causes RelationRestrictionForRelation() to return the child's restriction
instead of the parent's. Since Vars in plannerInfo->parse still reference the
parent's original rtable position, RequiredAttrNumbersForRelationInternal()
finds no matching Vars, causing all columns to be replaced with NULL.

Fix by adding an originalRteIndex parameter to RequiredAttrNumbersForRelation()
that also searches at the RTE's original position in the query's rtable when it
differs from the restriction's index.

Fixes: #8553
@colm-mchugh colm-mchugh force-pushed the feature/inheritance-left-join-fix branch from 100255d to d06e2c0 Compare May 20, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong results: WHERE on inheritance parent column drops all rows when cross-joined with a distributed table through LEFT JOIN ... ON FALSE

1 participant