From c7d2b86fc6defc22a003198f26147aa103f9dbeb Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Tue, 26 Nov 2024 15:08:55 -0800 Subject: [PATCH] reorder task and task_attempt primary key This reorders the task and task_attempt primary keys such that the queue name prefixes the index name. Because queues are contained within the same physical table, this prefix helps ensure better performance when selecting tasks from the queue. Closes #68 --- migrations/20241126224448_5.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 migrations/20241126224448_5.sql diff --git a/migrations/20241126224448_5.sql b/migrations/20241126224448_5.sql new file mode 100644 index 0000000..6e09f8d --- /dev/null +++ b/migrations/20241126224448_5.sql @@ -0,0 +1,15 @@ +-- Force anything running this migration to use the right search path. +set local search_path to underway; + +alter table underway.task_attempt drop constraint task_attempt_task_id_task_queue_name_fkey; + +alter table underway.task drop constraint task_pkey; +alter table underway.task add constraint task_pkey +primary key (task_queue_name, id); + +alter table underway.task_attempt drop constraint task_attempt_pkey; +alter table underway.task_attempt add constraint task_attempt_pkey +primary key (task_queue_name, task_id, attempt_number); + +alter table underway.task_attempt add constraint task_attempt_task_queue_name_task_id_fkey +foreign key (task_queue_name, task_id) references underway.task(task_queue_name, id) on delete cascade;