-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update indexes to improve performance of fetch_job
- Loading branch information
Showing
3 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
procrastinate/contrib/django/migrations/0031_add_indexes_for_fetch_job.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from __future__ import annotations | ||
|
||
from django.db import migrations | ||
|
||
from .. import migrations_utils | ||
|
||
|
||
class Migration(migrations.Migration): | ||
operations = [ | ||
migrations_utils.RunProcrastinateSQL( | ||
name="02.14.01_01_add_indexes_for_fetch_job.sql" | ||
) | ||
] | ||
name = "0031_add_indexes_for_fetch_job" | ||
dependencies = [("procrastinate", "0030_alter_procrastinateevent_options")] |
7 changes: 7 additions & 0 deletions
7
procrastinate/sql/migrations/02.14.01_01_add_indexes_for_fetch_job.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
-- recreate procrastinate_jobs_id_lock_idx index by adding aborting status to the filter so that it can be used by the fetch job function | ||
CREATE INDEX procrastinate_jobs_id_lock_idx_temp ON procrastinate_jobs (id, lock) WHERE status = ANY (ARRAY['todo'::procrastinate_job_status, 'doing'::procrastinate_job_status, 'aborting'::procrastinate_job_status]); | ||
DROP INDEX procrastinate_jobs_id_lock_idx; | ||
ALTER INDEX procrastinate_jobs_id_lock_idx_temp RENAME TO procrastinate_jobs_id_lock_idx; | ||
|
||
-- add index to avoid seq scan of outer loop in the fetch job function | ||
CREATE INDEX procrastinate_jobs_priority_idx ON procrastinate_jobs(priority desc, id asc) WHERE (status = 'todo'::procrastinate_job_status); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters