-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Improve postgres duplicate job detection performance
Previously, neoq would query to see if new jobs' (fingerprint, status) tuple were unique. This change adds a unique index on (fingerprint, status) and simply allows unique key constraint violations to be returned from `Enqueue` instead. This prevents one additional query for every new queue item.
- Loading branch information
Showing
6 changed files
with
71 additions
and
34 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
backends/postgres/migrations/20230902105301_make_fingerprint_index_unique.down.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,2 @@ | ||
CREATE INDEX IF NOT EXISTS neoq_jobs_fingerprint_idx ON neoq_jobs (fingerprint, status); | ||
DROP INDEX IF EXISTS neoq_jobs_fingerprint_unique_idx; |
3 changes: 3 additions & 0 deletions
3
backends/postgres/migrations/20230902105301_make_fingerprint_index_unique.up.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,3 @@ | ||
--- This unique partial index prevents multiple unprocessed jobs with the same payload from being queued | ||
CREATE UNIQUE INDEX IF NOT EXISTS neoq_jobs_fingerprint_unique_idx ON neoq_jobs (fingerprint, status) WHERE NOT (status = 'processed'); | ||
DROP INDEX IF EXISTS neoq_jobs_fingerprint_idx; |
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
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
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
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