Skip to content

Commit

Permalink
Include task_id in effective primary keys for all tables. (#2074)
Browse files Browse the repository at this point in the history
This updates the aggregation_jobs & collection_jobs tables; previously, only the direct ID (aggregation_job_id or collection_job_id) was treated as the effective primary key. For both tables, this will allow an indexed lookup where previously a scan was required (in get_aggregation_job/get_collection_job, respectively), though in both cases the most direct ID could be looked-up by index and then the task ID checked.
  • Loading branch information
branlwyd authored Oct 6, 2023
1 parent 6fbdf3c commit 75a027c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions db/00000000000001_initial_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ CREATE TABLE aggregation_jobs(
updated_at TIMESTAMP NOT NULL, -- when the row was last changed
updated_by TEXT NOT NULL, -- the name of the transaction that last updated the row

CONSTRAINT aggregation_jobs_unique_id UNIQUE(aggregation_job_id),
CONSTRAINT aggregation_jobs_unique_id UNIQUE(task_id, aggregation_job_id),
CONSTRAINT fk_task_id FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
);
CREATE INDEX aggregation_jobs_state_and_lease_expiry ON aggregation_jobs(state, lease_expiry) WHERE state = 'IN_PROGRESS';
Expand Down Expand Up @@ -334,7 +334,7 @@ CREATE TABLE collection_jobs(
updated_at TIMESTAMP NOT NULL, -- when the row was last changed
updated_by TEXT NOT NULL, -- the name of the transaction that last updated the row

CONSTRAINT collection_jobs_unique_id UNIQUE(collection_job_id),
CONSTRAINT collection_jobs_unique_id UNIQUE(task_id, collection_job_id),
CONSTRAINT fk_task_id FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE
);
CREATE INDEX collection_jobs_task_id_batch_id ON collection_jobs(task_id, batch_identifier);
Expand Down

0 comments on commit 75a027c

Please sign in to comment.