Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query: shortcircuit query when result is guaranteed to be empty #459

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

galdre
Copy link
Contributor

@galdre galdre commented Feb 13, 2024

The -collect fn, run at the end of a query, correctly shortcircuits with the following comment: "one empty rel means final set has to be empty"

However, while processing the query clauses, there was no shortcircuit. Because the implementation of lookup-pattern is agnostic to existing rels, this means that the query engine will continue slicing the indexes for every tuple that could possibly match every clause until all clauses are exhausted.

This is a one-line change to add a shortcircuit in resolve-clause if any existing relation is empty. The check is cheap, and it should provide a substantial performance boost in many common cases.

Motivation: substantial performance boost for a real-world app

… empty.

The `-collect` fn, run at the end of a query, correctly shortcircuits with the
following comment: "one empty rel means final set has to be empty"

However, while processing the query clauses, there was no shortcircuit.
Also, since the implementation of `lookup-pattern` is agnostic to
existing rels, this means that attempts to write short-circuiting
clauses at the top of a complex query have very little effect: the
query engine will continue querying the indexes for every tuple that
could possibly match every clause.

This adds a shortcircuit in `resolve-clause` if any existing relation
is empty. The check is cheap, and it should provide a substantial
performance boost in many common cases.
@tonsky tonsky merged commit 1b39bf2 into tonsky:master Feb 14, 2024
@tonsky
Copy link
Owner

tonsky commented Feb 14, 2024

Awesome! Thank you!

@tonsky
Copy link
Owner

tonsky commented Feb 14, 2024

Published 1.6.2

@galdre galdre deleted the galdre/shortcircuit-query branch February 14, 2024 21:49
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.

None yet

2 participants