Code review comment for lp:~adeuring/launchpad/fix-broken-initialisation-of-bug-latest-patch-uploaded

Revision history for this message
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_patch_uploaded = LatestPatch.datecreated
FROM (
    SELECT BugAttachment.bug, max(Message.datecreated) AS datecreated
    FROM BugAttachment, Message
    WHERE BugAttachment.message = Message.id
        AND BugAttachment.type = 1
    GROUP BY BugAttachment.bug
    ) AS LatestPatch
WHERE LatestPatch.bug = Bug.id;

The index is good.

« Back to merge proposal