From 655547d5dbb5c9ad2f534a7ace3b9fdae3fbf227 Mon Sep 17 00:00:00 2001
From: Diego Tavares <dtavares@imageworks.com>
Date: Tue, 11 Jul 2023 14:24:56 -0700
Subject: [PATCH] Add new indexes to improve booking performance

After the changes on the gpu PR https://github.com/AcademySoftwareFoundation/OpenCue/pull/924
the performance of the booking query degraded up to 4 times the previous
throughput. Creating some indexes for columns that changed names seems to
have fixed the problem.

Signed-off-by: Diego Tavares <dtavares@imageworks.com>
---
 .../postgres/migrations/V18_Add_New_Indexes   | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)
 create mode 100644 cuebot/src/main/resources/conf/ddl/postgres/migrations/V18_Add_New_Indexes

diff --git a/cuebot/src/main/resources/conf/ddl/postgres/migrations/V18_Add_New_Indexes b/cuebot/src/main/resources/conf/ddl/postgres/migrations/V18_Add_New_Indexes
new file mode 100644
index 000000000..a213ba6f4
--- /dev/null
+++ b/cuebot/src/main/resources/conf/ddl/postgres/migrations/V18_Add_New_Indexes
@@ -0,0 +1,32 @@
+
+--Performance issue, Created new index on column int_gpus_min
+
+-- DROP INDEX IF EXISTS public.i_layer_int_gpu_mem_min;
+
+CREATE INDEX IF NOT EXISTS i_layer_int_gpu_mem_min
+    ON public.layer USING btree
+    (int_gpus_min ASC NULLS LAST)
+    TABLESPACE pg_default;
+    
+-- DROP INDEX IF EXISTS public.i_layer_int_gpu_mem_min_1;
+
+CREATE INDEX IF NOT EXISTS i_layer_int_gpu_mem_min_1
+    ON public.layer USING btree
+    (int_gpu_min ASC NULLS LAST)
+    TABLESPACE pg_default;
+
+-- Created Indexes on Jun-26-2023 to improve query performance
+
+create index concurrently i_layer_int_cores_max on layer(int_cores_max);
+
+create index concurrently i_job_resource_int_priority on job_resource(int_priority);
+
+create index concurrently i_job_int_min_cores on job(int_min_cores);
+
+create index concurrently  i_layer_limit_pk_layer on layer_limit(pk_layer);
+
+create index concurrently i_folder_resource_int_cores on folder_resource(int_cores);
+
+create index concurrently  i_job_ts_updated on job(ts_updated);
+
+create index concurrently i_layer_str_tags on layer(str_tags);