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

https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/database/count/reltuples_count_strategy.rb#L74

      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 Mar 12, 2020 by Alina Mihaila
Assignee Loading
Time tracking Loading