Merge lp://staging/~gmb/launchpad/bugjob-indices-bug-539382 into lp://staging/launchpad/db-devel
Proposed by
Graham Binns
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Graham Binns | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp://staging/~gmb/launchpad/bugjob-indices-bug-539382 | ||||
Merge into: | lp://staging/launchpad/db-devel | ||||
Diff against target: |
15 lines (+11/-0) 1 file modified
database/schema/patch-2207-53-0.sql (+11/-0) |
||||
To merge this branch: | bzr merge lp://staging/~gmb/launchpad/bugjob-indices-bug-539382 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Björn Tillenius (community) | db | Approve | |
Stuart Bishop (community) | db | Approve | |
Review via email: mp+24239@code.staging.launchpad.net |
Commit message
Indices have been added to BugJob and Job to speed up the queries that search for ready CalculateBugHea
Description of the change
This branch adds indices to BugJob and Job on the fields that are used when looking for existing CalculateBugHea
It may be that we ultimately need to not do the check for existing jobs in the create() method, and instead ensure that only one job is run at a time, but either way these indices should improve performance of several BugJob and Job related queries.
To post a comment you must log in.
I can't recall why I let this table get created without indexes. Possibly because I didn't think it should get as big as it has (2.5 million jobs, with nearly 1 million of them completed over a month ago that nobody has bothered to garbage collect).
Should BugJob.job be UNIQUE?
Should BugJob.bug be UNIQUE?
Should (BugJob.bug, BugJob.job) be UNIQUE?
To know if the indexes are going to be used, I'll need some more information about the queries being made. In particular, if we search for 'jobs for bug NNN with type ZZZ' we should create an index on (bug, job_type) rather than separate indexes on bug and job_type. If we are querying for 'All bug jobs of type ZZZ' then we should separate the indexes.
Allocated patch number is patch-2207-53-0.sql
Indexes should be named with a __idx suffix, as per the following. If we are creating UNIQUE constraints instead, we will create them with a __key suffix.
SET client_ min_messages= ERROR;
-- Indices for BugJob _job_type_ _idx ON BugJob(job_type);
CREATE INDEX bugjob__job__idx ON BugJob(job);
CREATE INDEX bugjob__bug__idx ON BugJob(bug);
CREATE INDEX bugjob_
-- Indices for Job start__ idx ON Job(scheduled_ start); expires_ _idx ON Job(lease_expires);
CREATE INDEX job__scheduled_
CREATE INDEX job__lease_
INSERT INTO LaunchpadDataba seRevision VALUES (2207, 53, 0);