Comment 3 for bug 659129

Revision history for this message
Stuart Bishop (stub) wrote :

Two causes of slowdown in slow COUNT query: Joining with Person is unnecessary, and the DISTINCT in the subselect is unnecessary. The DISTINCT is the big slowdown. The following query performs in under a second, as opposed to around 45 seconds on a production slave:

SELECT COUNT(*)
FROM Archive, ValidPersonOrTeamCache
WHERE
    Archive.purpose = 2
    AND Archive.distribution = 1
    AND Archive.owner = ValidPersonOrTeamCache.id
    AND Archive.id IN (
        SELECT archive
        FROM SourcepackagePublishingHistory
        WHERE status IN (2, 1))
    AND Archive.fti @@ ftq('munin')
    AND Archive.private = FALSE
    AND Archive.enabled = TRUE AND (1=1);