-
-
Notifications
You must be signed in to change notification settings - Fork 116
Use _counts to speed up counts #215
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
Comments
Idea: a |
Thought: maybe there should be a One way that could happen is if a table is dropped and recreated - the counts in the |
def cached_counts(self, tables=None):
sql = "select [table], count from {}".format(self._counts_table_name)
if tables:
sql += " where [table] in ({})".format(", ".join("?" for table in tables))
return {r[0]: r[1] for r in self.execute(sql, tables).fetchall()} |
Here's the current sqlite-utils/sqlite_utils/db.py Lines 597 to 609 in 036ec6d
It's implemented on I'm a bit cautious about making that property so much more complex. In order to decide if it should try the
Then it can do the query, and if the query fails it can fall back on the |
Alternative implementation: provided select count from _counts where [table] = ? If the query fails to return a result OR throws an error because the table doesn't exist, run the |
Another option: on creation of the |
Idea: a |
I'm having second thoughts about this being the default behaviour. It's pretty weird. I feel like HUGE databases that need this are rare, so having it on by default doesn't make sense. |
So if you instantiate the |
Utility mechanism for taking advantage of the new
_counts
table from #212 would be nice.These can trigger automatically if the
_counts
table exists, but sincesqlite-utils
needs to work against any existing database there should be a way of opting out of this optimization.The text was updated successfully, but these errors were encountered: