Merge lp:~adeuring/launchpad/fix-broken-initialisation-of-bug-latest-patch-uploaded into lp:launchpad/db-devel
| Status: | Merged |
|---|---|
| Merged at revision: | not available |
| Proposed branch: | lp:~adeuring/launchpad/fix-broken-initialisation-of-bug-latest-patch-uploaded |
| Merge into: | lp:launchpad/db-devel |
| Diff against target: |
25 lines (+12/-4) 1 file modified
database/schema/patch-2207-29-0.sql (+12/-4) |
| To merge this branch: | bzr merge lp:~adeuring/launchpad/fix-broken-initialisation-of-bug-latest-patch-uploaded |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Stuart Bishop | db | 2010-02-04 | Approve on 2010-02-15 |
| Jonathan Lange (community) | database | 2010-02-04 | Approve on 2010-02-11 |
|
Review via email:
|
|||
| Abel Deuring (adeuring) wrote : | # |
| Abel Deuring (adeuring) wrote : | # |
I added an index for bugattachment.bug.
jtv noticed that we don't have such an index at present. Without it, the inital update query for the column bug.latest_
| Abel Deuring (adeuring) wrote : | # |
I added an index for bugattachment.bug.
jtv noticed that we don't have such an index at present. Without it, the inital update query for the column bug.latest_
| Stuart Bishop (stub) wrote : | # |
I think the following is better to populate the new column (it avoids the noise from the SELECT output, and will be faster as there is no stored procedure call overhead):
UPDATE Bug
SET latest_
FROM (
SELECT BugAttachment.bug, max(Message.
FROM BugAttachment, Message
WHERE BugAttachment.
AND BugAttachment.type = 1
GROUP BY BugAttachment.bug
) AS LatestPatch
WHERE LatestPatch.bug = Bug.id;
The index is good.

The original query to initialise the new column bug.latest_ patch_uploaded contained a "teensy weensy little mistake", to quote jtv.
The naively nested SELECTs let the query run for a ridiculously long time. The new version should be better. There is no need to access the tbale Bug at all in the SELECT statement -- all we need are the IDs of bugs that need to be updated.