Comment 10 for bug 659129

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

The slow query in that OOPS is:

SELECT COUNT(*) FROM Archive, Person, ValidPersonOrTeamCache
WHERE
    Archive.purpose = 2 AND Archive.distribution = 1
    AND Person.id = Archive.owner
    AND Person.id = ValidPersonOrTeamCache.id
    AND Archive.private = FALSE AND Archive.enabled = TRUE;

This can be sped up by removing the unnecessary join with Person:

SELECT COUNT(*) FROM Archive, ValidPersonOrTeamCache
WHERE
    Archive.purpose = 2 AND Archive.distribution = 1
    AND Archive.owner = ValidPersonOrTeamCache.id
    AND Archive.private = FALSE AND Archive.enabled = TRUE;

If you need Person in there later, we need to not join with ValidPersonOrTeamCache and add that logic to the query:

SELECT COUNT(*)
FROM Archive
JOIN Person ON Person.id = Archive.owner
LEFT OUTER JOIN EmailAddress ON EmailAddress.person = Person.id
LEFT OUTER JOIN Account ON Account.id = EmailAddress.account
WHERE
    Archive.purpose = 2 AND Archive.distribution = 1
    AND Archive.private = FALSE AND Archive.enabled = TRUE
    AND (
        (Person.teamowner IS NOT NULL AND Person.merged IS NULL)
        OR (Person.teamowner IS NULL AND Account.status = 20
            AND EmailAddress.status = 4));

If you choose the last option, please cite Bug #660400 with an XXX.