Skip to content

fix(sql): handle correlated subqueries over union#19607

Open
sundy-li wants to merge 1 commit intodatabendlabs:mainfrom
sundy-li:issue-19574-20260324-2019
Open

fix(sql): handle correlated subqueries over union#19607
sundy-li wants to merge 1 commit intodatabendlabs:mainfrom
sundy-li:issue-19574-20260324-2019

Conversation

@sundy-li
Copy link
Copy Markdown
Member

@sundy-li sundy-li commented Mar 24, 2026

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  • preserve correlated-column mappings across decorrelated UNION / UNION ALL branches
  • add replay and service regressions for correlated EXISTS subqueries over set operations

Changes

  • compute branch-level need_cross_join in flatten_sub_union_all whenever a branch does not cover the full correlated key set
  • replace unwrap()-based correlated mapping lookups with get_derived() so missing mappings surface as errors instead of panics
  • add shared optimizer replay cases for the reported UNION and UNION ALL repros
  • add service-side regression tests for the same two query shapes

Tests

  • Unit Test

  • Logic Test

  • Benchmark Test

  • No Test - Pair with the reviewer to explain why

  • TEST_SUBDIR=regressions cargo test --package databend-common-sql --test it -- planner::test_lite_replay_service_optimizer_cases --exact --nocapture

  • cargo fmt --all

Type of change

  • Bug fix

Fixes #19574


This change is Reviewable

@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Mar 24, 2026
@sundy-li sundy-li added the agent-reviewable Ready for agent review label Mar 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🤖 CI Job Analysis

Workflow: 23490233034

📊 Summary

  • Total Jobs: 86
  • Failed Jobs: 1
  • Retryable: 0
  • Code Issues: 1

NO RETRY NEEDED

All failures appear to be code/test issues requiring manual fixes.

🔍 Job Details

  • linux / test_unit: Not retryable (Code/Test)

🤖 About

Automated analysis using job annotations to distinguish infrastructure issues (auto-retried) from code/test issues (manual fixes needed).

@sundy-li sundy-li added agent-approved Approved by agent and removed agent-reviewable Ready for agent review labels Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved Approved by agent pr-bugfix this PR patches a bug in codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Panic in decorrelate optimizer with correlated subquery over UNION

1 participant