Skip to content

Fix MIR's could_run_expensive_function's quadraticness#35470

Open
ggevay wants to merge 1 commit intoMaterializeInc:mainfrom
ggevay:could_run_expensive_function-mir
Open

Fix MIR's could_run_expensive_function's quadraticness#35470
ggevay wants to merge 1 commit intoMaterializeInc:mainfrom
ggevay:could_run_expensive_function-mir

Conversation

@ggevay
Copy link
Contributor

@ggevay ggevay commented Mar 13, 2026

MIR's could_run_expensive_function was accidentally quadratic. try_visit_scalars was visiting the entire tree, and the visit_pre was running this for every node of the tree. This is a really bad performance bug, because this runs on the coordinator's main task, so any big SUBSCRIBE (in terms of plan size) would make the coordinator stuck for a while.

(Follow-up to #35413, which was fixing a bug in HIR's could_run_expensive_function; cc @def- )

@ggevay ggevay added T-performance Theme: performance improvements A-ADAPTER Topics related to the ADAPTER layer labels Mar 13, 2026
@github-actions
Copy link

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).

@def-
Copy link
Contributor

def- commented Mar 16, 2026

Merging #35413 now

@ggevay ggevay force-pushed the could_run_expensive_function-mir branch 2 times, most recently from c375ae7 to e03dc78 Compare March 17, 2026 11:07
@ggevay ggevay marked this pull request as ready for review March 17, 2026 11:08
@ggevay ggevay requested review from a team as code owners March 17, 2026 11:08
@ggevay ggevay requested a review from ohbadiah March 17, 2026 11:08
ggevay added a commit that referenced this pull request Mar 17, 2026
`auto_run_on_catalog_server` was not looking inside the EXPLAIN plan
when it was a SUBSCRIBE, so it was just falling back to the default
case. (Actual, i.e. non-explain SUBSCRIBEs are correct.)

Motivation: Needed for testing
#35470
@ggevay ggevay force-pushed the could_run_expensive_function-mir branch from e03dc78 to 558c4a5 Compare March 17, 2026 19:41
maheshwarip pushed a commit that referenced this pull request Mar 19, 2026
`auto_run_on_catalog_server` was not looking inside the EXPLAIN plan
when it was a SUBSCRIBE, so it was just falling back to the default
case. (Actual, i.e. non-explain SUBSCRIBEs are correct.)

Motivation: Needed for testing
#35470
@frankmcsherry frankmcsherry self-requested a review March 20, 2026 15:20
Copy link
Contributor

@frankmcsherry frankmcsherry left a comment

Choose a reason for hiding this comment

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

The code looks good. I think it could benefit from a comment about what that hunk of code is trying to do, for future generations. Fine to do this async after it merges, but I can't actually tell what the stack of closures does without reading the code (and .. we shouldn't want to have to read the code, imo).

@ggevay ggevay force-pushed the could_run_expensive_function-mir branch from 558c4a5 to c2b3849 Compare March 20, 2026 16:03
@ggevay
Copy link
Contributor Author

ggevay commented Mar 20, 2026

The function does have a doc comment with a high-level overview (which I've now tweaked a bit). Or did you mean something like an intermediate-level comment, which would be more detailed than the doc comment but less detailed than the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ADAPTER Topics related to the ADAPTER layer T-performance Theme: performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants