Skip to content

Fix union equivalence schema rewrite with stale constants#23375

Open
xudong963 wants to merge 1 commit into
apache:mainfrom
xudong963:xudong963/fix-union-equivalence-stale-constants
Open

Fix union equivalence schema rewrite with stale constants#23375
xudong963 wants to merge 1 commit into
apache:mainfrom
xudong963:xudong963/fix-union-equivalence-stale-constants

Conversation

@xudong963

@xudong963 xudong963 commented Jul 7, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

UnionExec::try_new can panic while computing equivalence properties if stale constant metadata is carried across a projection and then rewritten to the union output schema.

In the observed shape, a filter such as ticker = 'ESU6' can leave a uniform string constant in equivalence properties. After a parent projection drops ticker, union property schema rewriting can see the remaining column slot as a timestamp column and attempt to cast 'ESU6' to Timestamp, which fails during planning.

Equivalence constants are optimizer metadata, so an unrepresentable constant after schema rewrite should be discarded rather than failing query planning.

What changes are included in this PR?

  • Drops a uniform constant during EquivalenceProperties::with_new_schema if its value cannot be cast to the rewritten expression type.
  • Removes trivial equivalence classes after dropping such constants.
  • Propagates UnionExec::compute_properties errors from UnionExec::try_new instead of unwrapping.
  • Adds a regression test for union equivalence schema rewrite with an unrepresentable stale constant value.

Are these changes tested?

Yes:

Are there any user-facing changes?

No API change. This prevents a planner panic for affected UNION ALL + filter + projection query shapes.

@github-actions github-actions Bot added physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate labels Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnionExec can panic when stale equivalence constants are rewritten after projection

1 participant