Skip to content

Fix counting of groups in admin dashboard

Stan Hu requested to merge sh-skip-sti-tables-reltuples into master

This merge request does two things:

  1. Ignore tables that use STI in reltuples count strategy.

    Models that use Rails' single-type inheritance, such as Group and CiService, need an additional WHERE clause to count the total properly, which isn't supported by the reltuples strategy. For now, we just omit these from the statistics sampling and rely on the other strategies to get this data.

  2. Makes the tablesample count strategy work properly with STI models.

    Models such as Group needs a WHERE clause to distinguish it from namespaces. We now add in the WHERE clause if STI is in use.

Even the exact count for Group isn't that expensive on GitLab.com:

[ gprd ] production> Group.count
D, [2019-03-12T06:52:05.142944 #12496] DEBUG -- :    (396.5ms)  SELECT COUNT(*) FROM "namespaces" WHERE "namespaces"."type" IN ('Group')
=> 811129
Edited by Stan Hu

Merge request reports