Query on Bugs front page timing out

Bug #518965 reported by Jeroen T. Vermeulen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Launchpad itself
New
Undecided
Unassigned

Bug Description

I'm getting timeouts on the Bugs front page like OOPS-1497ED764. This is apparently distinct from bug 517798, a fix for which is underway.

The query that times out is:

SELECT *
FROM (
    SELECT *
    FROM Bug
    WHERE (
        Bug.private = FALSE OR
        Bug.id in (
            SELECT Bug.id
            FROM Bug, BugSubscription, TeamParticipation
           WHERE
               -- Bug.private AND
               Bug.id = BugSubscription.bug AND
               TeamParticipation.person = 2106201 AND
               BugSubscription.person = TeamParticipation.team))
    ORDER BY Bug.datecreated DESC, Bug.id DESC
    LIMIT 1) AS "_tmp" LIMIT 1;

This consistently takes 2,400—2,800 ms for me on staging. The problem seems to be in sorting the rows by datecreated and id (with id as a nice tie-breaker). There is an index for datecreated, but not one for (datecreated, id), and sorting the data at the end of the query for some reason turns out to be very costly.

Execution time drops by a whopping 4 orders of magnitude for me when I add a query for exactly this ordering:

    CREATE INDEX bug__datecreated__id__idx ON Bug(datecreated, id);

(After this I'm guessing that the index on datecreated alone probably no longer pulls its weight, so consider dropping that at some point).

Related branches

tags: added: oops
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Oh, I accidentally included a comment in that query: a "Bug.private AND" clause in the sub-query. That was an earlier suggestion to limit the subquery to proviate bugs. It may help further, especially in combination with a partial index on private bugs, but probably not dramatically so. Let's hope that that other speedup is enough for now. :-)

tags: added: timeout
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.