Statistics are not updated in time for approximate counters usage
Summary
Table statistics are not updated in time for approximate counters usage
Output of checks
Output of query from production replica
Get the statistics in ruby
def get_statistics(table_names, check_statistics: true)
time = 1.hour.ago
query = PgClass.joins("LEFT JOIN pg_stat_user_tables USING (relname)")
.where(relname: table_names)
.select('pg_class.relname AS table_name, reltuples::bigint AS estimate')
if check_statistics
query = query.where('last_vacuum > ? OR last_autovacuum > ? OR last_analyze > ? OR last_autoanalyze > ?',
time, time, time, time)
end
query
end
Edited by Alina Mihaila