Skip to content

perf: deduplicate found expressions with an IndexSet - #26474

Merged
jayzhan211 merged 2 commits into
apache:mainfrom
Braedon-Wooding-Displayr:perf/find-exprs-dedup-hash
Oct 26, 2026
Merged

jayzhan211 merged 2 commits into
apache:mainfrom
Braedon-Wooding-Displayr:perf/find-exprs-dedup-hash

Conversation

@Braedon-Wooding-Displayr

@Braedon-Wooding-Displayr Braedon-Wooding-Displayr commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

I've got a few fixes to upstream so just starting with small ones.

Which issue does this PR close?

Rationale for this change

find_exprs_in_exprs and find_exprs_in_expr deduplicate with Vec::contains, which is quadratic in the number of distinct matches. On 20,000 distinct aggregates find_aggregate_exprs takes 932 ms; with this change it takes 2.8 ms (release build, see the issue for the full table).

What changes are included in this PR?

Both functions now collect into a single index set.

Are there any user-facing changes?

No

@github-actions github-actions Bot added the logical-expr Logical plan and expressions label Oct 18, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.89%. Comparing base (3470bd0) to head (9d76a7d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #26474      +/-   ##
==========================================
- Coverage   82.90%   82.89%   -0.01%     
==========================================
  Files        1154     1154              
  Lines      457654   457680      +26     
  Branches   457654   457680      +26     
==========================================
+ Hits       379398   379412      +14     
- Misses      55252    55261       +9     
- Partials    23004    23007       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread datafusion/expr/src/utils.rs Outdated
Comment on lines +879 to +881
let mut found = IndexSet::new();
collect_exprs_in_expr(expr, test_fn, &mut found);
found.into_iter().collect()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: this can just delegate to find_exprs_in_exprs, which leaves one place that builds the set:

-    let mut found = IndexSet::new();
-    collect_exprs_in_expr(expr, test_fn, &mut found);
-    found.into_iter().collect()
+    find_exprs_in_exprs(std::iter::once(expr), test_fn)

@alamb

alamb commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

This PR appears to be waiting on the author to respond to reviewer feedback so marking as draft. Please mark ready to review when it is ready for another look

@alamb
alamb marked this pull request as draft October 24, 2026 10:04
@Braedon-Wooding-Displayr
Braedon-Wooding-Displayr marked this pull request as ready for review October 25, 2026 23:52
@Braedon-Wooding-Displayr

Copy link
Copy Markdown
Contributor Author

Sorry! Australian timezones mean that it sits over weekends sometimes!

I've just fixed and rebase + pushed, should be ready for merge now @alamb

@jayzhan211
jayzhan211 added this pull request to the merge queue Oct 26, 2026
@jayzhan211

Copy link
Copy Markdown
Contributor

Thanks @Braedon-Wooding-Displayr !

Merged via the queue into apache:main with commit 350ca76 Oct 26, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Planning a query with many aggregate or window expressions slows down quadratically

4 participants