Merge lp://qastaging/~cjwatson/launchpad/db-bugsummary-statement-triggers into lp://qastaging/launchpad/db-devel

Proposed by Colin Watson
Status: Rejected
Rejected by: Colin Watson
Proposed branch: lp://qastaging/~cjwatson/launchpad/db-bugsummary-statement-triggers
Merge into: lp://qastaging/launchpad/db-devel
Diff against target: 274 lines (+255/-3)
2 files modified
database/schema/patch-2210-06-0.sql (+251/-0)
database/schema/security.cfg (+4/-3)
To merge this branch: bzr merge lp://qastaging/~cjwatson/launchpad/db-bugsummary-statement-triggers
Reviewer Review Type Date Requested Status
Stuart Bishop db Pending
Launchpad code reviewers db Pending
Review via email: mp+371297@code.qastaging.launchpad.net

Commit message

Rewrite BugSummary triggers to be statement-level.

Description of the change

Rewrite the BugSummaryJournal maintenance triggers to make use of the new transition tables provided to AFTER ... FOR EACH STATEMENT triggers as of PostgreSQL 10. Instead of using row-level triggers which accumulate changes in a temporary table and flush it into the journal, we now write directly to the journal at the end of each statement.

There's a considerable amount of complexity here due to transition tables only being visible in the trigger function itself, not in functions that it calls. I used a combination of LATERAL and dynamic commands to minimise the amount of repeated code resulting from this. This does mean that the outermost part of each trigger function's query needs to be replanned each time the trigger runs, but I don't expect that to make a significant performance difference.

The transformations related to bug tags aren't completely obvious. I eliminated summarise_bug and unsummarise_bug from the call chain, as they didn't seem to be pulling their weight. When BugTag is changed, rather than decrementing/incrementing all the BugSummary rows that the changed bugs expand to, it now makes more sense to do so only for the rows relating to the changed tags. This necessitated extending bugsummary_journal_bugtaskflat and friends to take an array of tags, so it now processes all tags on the bug plus NULL when handling BugTaskFlat changes, and only the changed tags when handling BugTag changes.

I can't say for sure whether this will fix the periodic bug update timeouts we've been seeing, since we've never completely got to the bottom of their cause. However, reducing the number of times the trigger functions need to be called and eliminating their use of an explicit temporary table seem likely to improve matters.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Unmerged revisions

14125. By Colin Watson

Rewrite BugSummary triggers to be statement-level.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to status/vote changes: