-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
add lambda criteria for faster caching of queries #5380
Copy link
Copy link
Closed
Labels
alchemy 2goes along with the 2.0 milestone to aid in searchinggoes along with the 2.0 milestone to aid in searchingfeatureperformancewhere performance can be improved. add "bug" only if it's a performance degradationwhere performance can be improved. add "bug" only if it's a performance degradationsql
Milestone
Metadata
Metadata
Assignees
Labels
alchemy 2goes along with the 2.0 milestone to aid in searchinggoes along with the 2.0 milestone to aid in searchingfeatureperformancewhere performance can be improved. add "bug" only if it's a performance degradationwhere performance can be improved. add "bug" only if it's a performance degradationsql
in #4639 we propose a new "baked select". this has evolved a very long way since the proposal and transparent query caching is now present in Core and ORM, including that the ORM caches the entire "compile context" part of the Query which was the most expensive part. only remaining is the "ORM update / delete" part of it which I'm working on in #5160. I want to close #4639 once I add some new logging for it and maybe some more tests (it is currently tested via the existing baked query extension which builds on top of it, but this is not a complete test).
for here, we want to add the ability to specify criteria as lambdas, such as:
stmt = select(User).where(lambda: User.name == 'name')
The rationale here is to reduce the overhead of building up "User.name == 'name'" on every call, as well as that generating the cache key for this expression is expensive. whereas adding a lambda: that we only call once costs much less (in theory, as we want to read out the parameters from it also) and also for caching is very quick. The proof of concept for this is currently in https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/1616 and this would be presented as part of a new documentation section dedicated to query caching.