Skip to content

optimizer: Correct the comment on zero counts in the subquery-size guard#37501

Open
ggevay wants to merge 1 commit into
MaterializeInc:mainfrom
ggevay:gabor/guard-subquery-size-zero-comment
Open

optimizer: Correct the comment on zero counts in the subquery-size guard#37501
ggevay wants to merge 1 commit into
MaterializeInc:mainfrom
ggevay:gabor/guard-subquery-size-zero-comment

Conversation

@ggevay

@ggevay ggevay commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Comment-only change. Followup to #37155

The previous comment said constant folding folds an empty subquery's count to a literal 0, but folding an MIR count over an empty collection yields an empty collection, not a 0. The actual mechanism (verified by tracing the original failure from #37155 on the commit where it occurred): over a provably empty subquery body, EquivalencePropagation vacuously rewrites the guard's count(true) to count(null), ReduceElision then elides the Reduce into a literal 0 via on_unique, LiteralLifting substitutes that literal into the guard's argument, and FlatMapElimination eagerly evaluates table functions with all-literal arguments during optimization.

The previous comment said constant folding folds an empty subquery's
count to a literal 0, but folding an MIR count over an empty collection
yields an empty collection, not a 0. The actual mechanism (verified by
tracing the original failure from MaterializeInc#37155 on the commit where it
occurred): over a provably empty subquery body, EquivalencePropagation
vacuously rewrites the guard's count(true) to count(null), ReduceElision
then elides the Reduce into a literal 0 via on_unique, LiteralLifting
substitutes that literal into the guard's argument, and
FlatMapElimination eagerly evaluates table functions with all-literal
arguments during optimization.

Comment-only change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ggevay ggevay requested a review from a team as a code owner July 7, 2026 17:40
@ggevay ggevay added the A-optimization Area: query optimization and transformation label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-optimization Area: query optimization and transformation

1 participant