Fix; for query performance #2246
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
We wanted to see the
EXPLAIN ANALYSE
for'completed
,in_progress
anddequeue
queries;I've tested this with the following in the database;
For small numbers of items it is always faster to use a sequence scan as it avoids loading an index. Postgres seems to be smart enough to know when to switch from a sequence scan to an index scan depending on how many entries there are.
The below indexes are created off the basis of wanting to avoid any sequence scan where possible.
Completed
This needs an index on the column
completed_at
otherwise we get a full sequence scan on thecompleted_at
column c799d67. Similarly theerror
table needs an index onaid
to prevent a full sequence scan of the error table when we do a join on theartifact.id
6a6dadb.BEFORE
AFTER
In Progress
This query needs no new indexes. We do a full sequence scan of the job queue table. I'm not sure yet if this is avoidable or acceptable. I'm also not exactly sure what we are wanting from the query. Below is the current
EXPLAIN ANALYSE
outputBEFORE - EXPLAIN ANALYSE output
If the query is to get the jobs of currently
in_progress
requests I have updated the query in this commit; fe91155Which produces a more optimised;
AFTER - EXPLAIN ANALYSE output
Dequeue
This query needs no new indexes.
EXPLAIN ANALYSE output