Skip to content

sql: Simplify quantified comparisons in JOIN ON clauses#36065

Merged
def- merged 1 commit intoMaterializeInc:mainfrom
def-:pr-on-opt
Apr 15, 2026
Merged

sql: Simplify quantified comparisons in JOIN ON clauses#36065
def- merged 1 commit intoMaterializeInc:mainfrom
def-:pr-on-opt

Conversation

@def-
Copy link
Copy Markdown
Contributor

@def- def- commented Apr 14, 2026

This comes from #9623

@def- def- requested a review from ggevay April 14, 2026 09:13
@def- def- requested a review from a team as a code owner April 14, 2026 09:13
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for opening this PR! Here are a few tips to help make the review process smooth for everyone.

PR title guidelines

  • Use imperative mood: "Fix X" not "Fixed X" or "Fixes X"
  • Be specific: "Fix panic in catalog sync when controller restarts" not "Fix bug" or "Update catalog code"
  • Prefix with area if helpful: compute: , storage: , adapter: , sql:

Pre-merge checklist

  • The PR title is descriptive and will make sense in the git log.
  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).

Copy link
Copy Markdown
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

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

Hmm, thanks, this looks good to me!

But I'd say we should create a feature flag for it (on by default), because we'd like an escape hatch in case it causes a catastrophic performance regression at some user. It's extremely hard to fully anticipate the consequences of optimizer changes. Even though the HIR plan change of this PR is generally considered a positive change, there are tons of surprising non-monotonicities in the optimizer, in the sense that when the plan looks better at a certain stage of the pipeline, it often happens that the better-looking plan is handled worse by a later optimizer pipeline stage, and we end up with a regression overall. (See #35441 for more discussion on the evolvability of the optimizer.)

I've kicked off the random query parts of Nightly as a further precaution: https://buildkite.com/materialize/nightly/builds/15999

Comment thread src/sql/src/plan/transform_hir.rs Outdated
Comment thread test/sqllogictest/subquery.slt
@def- def- requested a review from a team as a code owner April 15, 2026 04:45
@def- def- requested a review from ggevay April 15, 2026 04:45
Copy link
Copy Markdown
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

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

Thank you!

Copy link
Copy Markdown
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

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

Wait, sorry, moment

Comment thread src/sql/src/plan/lowering.rs Outdated
transform_hir::try_simplify_quantified_comparisons(&mut other)?;
if context.config.enable_simplify_quantified_comparisons {
transform_hir::try_simplify_quantified_comparisons(&mut other)?;
}
Copy link
Copy Markdown
Contributor

@ggevay ggevay Apr 15, 2026

Choose a reason for hiding this comment

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

This would completely disable try_simplify_quantified_comparisons when the flag is off, so we'd have changed plans from before the PR with the flag both on and off. What I meant is to guard only the new part of try_simplify_quantified_comparisons with the feature flag, because the important thing is to be able to get back to the old plans by turning off the flag (if needed).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops, thanks a lot for catching!

Copy link
Copy Markdown
Contributor

@ggevay ggevay left a comment

Choose a reason for hiding this comment

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

LGTM, just a minor thing left

Comment thread src/sql/src/session/vars/definitions.rs Outdated
@def-
Copy link
Copy Markdown
Contributor Author

def- commented Apr 15, 2026

Thanks for the great reviews Gabor!

@def- def- enabled auto-merge (squash) April 15, 2026 13:50
@def- def- merged commit 6168aa9 into MaterializeInc:main Apr 15, 2026
119 checks passed
@def- def- deleted the pr-on-opt branch April 15, 2026 13:59
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.

2 participants