Skip to content

Fix segfault in EXPLAIN with LEFT JOIN and correlated subqueries (#8548)#8556

Open
colm-mchugh wants to merge 3 commits intomainfrom
feature/explain-segfault-fix
Open

Fix segfault in EXPLAIN with LEFT JOIN and correlated subqueries (#8548)#8556
colm-mchugh wants to merge 3 commits intomainfrom
feature/explain-segfault-fix

Conversation

@colm-mchugh
Copy link
Copy Markdown
Contributor

DESCRIPTION: Fix segfault in EXPLAIN with LEFT JOIN and correlated subqueries (#8548)

Fix by adding a NULL check that skips discarded subplan entries. This is needed because PostgreSQL's setrefs.c (set_plan_references) resolves AlternativeSubPlan nodes by picking one alternative and setting the discarded subplan entries to NULL in PlannedStmt->subplans. PlanContainsDistributedSubPlanRTE() iterated this list without a NULL check, hitting the segfault reported in #8548.

Also refactor the function to accept DistributedPlanningContext* instead of a raw List*, making it evident that we're iterating PostgreSQL's PlannedStmt->subplans (where NULL entries are expected).

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.78%. Comparing base (8b99e07) to head (41d0b80).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8556      +/-   ##
==========================================
- Coverage   88.79%   88.78%   -0.01%     
==========================================
  Files         287      287              
  Lines       64050    64053       +3     
  Branches     8054     8054              
==========================================
- Hits        56874    56871       -3     
- Misses       4849     4852       +3     
- Partials     2327     2330       +3     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@colm-mchugh colm-mchugh force-pushed the feature/explain-segfault-fix branch from 93614c1 to b2bbdd6 Compare April 30, 2026 14:51
Fix by adding a NULL check that skips discarded subplan entries.
This is needed because PostgreSQL's setrefs.c (set_plan_references)
resolves AlternativeSubPlan nodes by picking one alternative and
setting the discarded subplan entries to NULL in PlannedStmt->subplans.
PlanContainsDistributedSubPlanRTE() iterated this list without a NULL
check, hitting the segfault reported in #8548.

Also refactor the function to accept DistributedPlanningContext* instead
of a raw List*, making it evident that we're iterating PostgreSQL's
PlannedStmt->subplans (where NULL entries are expected).

Note: PG16 errors on the test query with 'outer joins and pseudo-const
quals are not supported', a known limitation with PG16. Added
alternative goldfile for PG16.
@ihalatci ihalatci removed this from the 14.1 milestone May 6, 2026
Copy link
Copy Markdown
Contributor

@ihalatci ihalatci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@colm-mchugh colm-mchugh enabled auto-merge (squash) May 6, 2026 15:40
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.

Segmentation fault on EXPLAIN of a query with LEFT JOIN to a distributed table and correlated subqueries in Citus 14.0.0 (PostgreSQL 18.1)

2 participants