Query on Bugs front page timing out
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
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__datecreate
(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
- Jonathan Lange (community): Approve
- Canonical Launchpad Engineering: Pending (db) requested
-
Diff: 9 lines (+5/-0)1 file modifieddatabase/schema/patch-2207-99-0.sql (+5/-0)
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. :-)