Skip to content

Conversation

@bplatz
Copy link
Contributor

@bplatz bplatz commented Jan 5, 2026

Improves query :where clause optimization by using greedy join ordering within optimizable segments and carrying forward in-scope variables across segments to prefer joins over cartesian expansion.

For queries with join patterns across references, this improves performance by an order of magnitude, in fact I'd consider this fix a bug that was introduced with the original optimization code as it makes certain types of queries less efficient than they likely were, however now they are faster with this fix.

Key changes

  • Greedy join ordering: prefers patterns that share variables with the current in-scope set, then chooses the lowest-selectivity pattern (stable tie-breaker).
  • Cross-segment var carry-forward: maintains an approximate “vars in scope” set as segments are processed.
  • No behavior change intended beyond improved ordering; same optimizer metadata is preserved for explain output.

bplatz added 2 commits January 4, 2026 10:52
…arrying forward bound variables across segments for improved execution efficiency.
@bplatz bplatz requested a review from a team January 5, 2026 11:20
Copy link
Contributor

@zonotope zonotope left a comment

Choose a reason for hiding this comment

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

I think there is a little overlap with #1182 and https://github.com/fluree/db/compare/feature/inline-multivariable-filters...feature/reorder-high-level-patterns?expand=1, but I can resolve the conflicts there.

lgtm

Base automatically changed from feature/index-dedupe to main January 7, 2026 21:15
Co-authored-by: Ben Lamothe <blamothe@flur.ee>
@bplatz bplatz merged commit 93f96d6 into main Jan 7, 2026
6 checks passed
@bplatz bplatz deleted the feature/optimizations branch January 7, 2026 21:19
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.

3 participants