Skip to content

feat(query): propagate column statistics through UNION ALL - #20224

Open
forsaken628 wants to merge 3 commits into
databendlabs:mainfrom
forsaken628:union-all
Open

feat(query): propagate column statistics through UNION ALL#20224
forsaken628 wants to merge 3 commits into
databendlabs:mainfrom
forsaken628:union-all

Conversation

@forsaken628

@forsaken628 forsaken628 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

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

Summary

  • Derive UNION ALL output column statistics by mapping child columns to output symbols, applying binder-inserted coercions, and merging min/max, NULL counts, and NDV.
  • Preserve statistics across lossless injective casts while leaving lossy and TRY_CAST conversions unknown.
  • Estimate merged NDV using histogram overlap when available and conservative join-aligned fallbacks otherwise. Clamp NDV to finite output domains to prevent internally inconsistent statistics.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@github-actions github-actions Bot added the pr-feature this PR introduces a new feature to the codebase label Jul 29, 2026
@forsaken628 forsaken628 changed the title feat(query): Union all stat feat(query): propagate column statistics through UNION ALL Jul 30, 2026
@forsaken628
forsaken628 marked this pull request as ready for review July 31, 2026 02:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 608f08a910

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/query/sql/src/planner/plans/union_all.rs
Comment thread src/query/sql/src/planner/plans/union_all.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature this PR introduces a new feature to the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants