-
Notifications
You must be signed in to change notification settings - Fork 148
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
Constraint information is not being cached #101
Comments
Thanks for catching the lack of caching on
I believe there's a fundamental constraint in SQLAlchemy's API for reflection that allows caching only within the context of reflecting a single table. I originally wrote the reflection code in this dialect with bulk queries like I do hope that using cache_info for the constraints query will speed things up a bit, but reflection across many tables is likely going to continue to be slow. |
PR for this in #102 |
Also see #103 for more thoughts on persisting schema info across multiple tables. |
I think your approach of doing just a few queries actually does work. You're right that the reflection methods that make up the public interface of the dialect generally require a table name, and that caching the result of those methods by itself won't reduce the number of queries that you have to make, but caching the result of your |
Wow. That is much more improvement than I expected. |
Well, previously that query in |
Thank you again for inspecting the code enough to figure out what was going on. I look forward to seeing whether this significantly improves some of my own use cases. |
And thank you for the quick response. :) It's an especially large gain for us because we often have a bunch of stale schemas in this cluster. Therefore, the |
This change is now merged to master. |
In
RedshiftDialect
, there are three methods,_get_all_relation_info
,_get_all_column_info
, and_get_all_constraint_info
, which query information about the whole cluster. These methods are called by several other methods which pass theirinfo_cache
argument down to one of the above methods. These methods, in turn, are called by other methods which, in most cases, pass down all of their keyword arguments. The one exception is_get_redshift_constraints
- this method is never called with the keyword arguments of its caller, and therefore never gets theinfo_cache
object that was passed in by SQLAlchemy. The result of this is that constraint information is never cached. When running something like alembic which does a lot of reflection, this can slow things down considerably because the dialect winds up querying information about the entire database every time alembic asks for anything.The text was updated successfully, but these errors were encountered: