-
-
Notifications
You must be signed in to change notification settings - Fork 400
perf: optimize sql for or queries #948
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me and runs on this library in ~13s instead of ~27s.
# If there is just one tag id, check the normal way | ||
elif len(tag_ids) == 1: | ||
bool_expressions.append( | ||
self.__entry_satisfies_expression(TagEntry.tag_id == tag_ids[0]) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my testing using __entry_has_all_tags
was slightly faster with one tag id. Sqlite will optimize out the group_by when just one tag_id is present. this can be checked with the query plan
rows = session.execute(text(f"EXPLAIN QUERY PLAN {query_full}")).fetchall()
for row in rows:
print(row)
This query takes 3 minutes for me on main. |
Summary
Currently there is one check for each term in an OrList. This change will extract the tags out of the OrList and put them in one check which is then combined with the remaining terms in the OrList.
Parent tags that expand to many children tags also benefit from this optimization.
Tasks Completed