Counting all of the rows in a large table is expensive - this is one of the main causes of performance problems in Datasette when running against large databases.
Carefully constructed SQL triggers could be used to maintain accurate cached counts for a table, by incrementing and decrementing a counter every time a row is inserted or deleted.
sqlite-utils already has a mechanism for creating triggers for FTS - the table.enable_fts(..., create_triggers=True) method. How about a similar mechanism for setting up triggers to maintain a count of table rows?
Counting all of the rows in a large table is expensive - this is one of the main causes of performance problems in Datasette when running against large databases.
Carefully constructed SQL triggers could be used to maintain accurate cached counts for a table, by incrementing and decrementing a counter every time a row is inserted or deleted.
sqlite-utilsalready has a mechanism for creating triggers for FTS - thetable.enable_fts(..., create_triggers=True)method. How about a similar mechanism for setting up triggers to maintain a count of table rows?