18943: consistency between modified_at/created_at indexes
authorPeter Amstutz <peter.amstutz@curii.com>
Fri, 1 Apr 2022 20:46:49 +0000 (16:46 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Fri, 1 Apr 2022 20:46:49 +0000 (16:46 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

services/api/db/migrate/20220401153101_fix_created_at_indexes.rb
services/api/db/structure.sql

index 72de6aa4dcda207e248f5630edd29cf2d7d7850c..308e69c9bc14ec5ea46aa2fe131f2cd83ebef943 100644 (file)
@@ -8,24 +8,26 @@ class FixCreatedAtIndexes < ActiveRecord::Migration[5.2]
   def up
     @@idxtables.each do |table|
       ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_created_at")
-      ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_created_at_uuid")
+      ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_created_at_and_uuid")
       ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_modified_at")
       ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_modified_at_uuid")
+      ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_modified_at_and_uuid")
 
-      ActiveRecord::Base.connection.execute("CREATE INDEX index_#{table.to_s}_on_created_at_uuid ON #{table.to_s} USING btree  (created_at, uuid)")
-      ActiveRecord::Base.connection.execute("CREATE INDEX index_#{table.to_s}_on_modified_at_uuid ON #{table.to_s} USING btree (modified_at desc, uuid desc)")
+      ActiveRecord::Base.connection.execute("CREATE INDEX IF NOT EXISTS index_#{table.to_s}_on_created_at_and_uuid ON #{table.to_s} USING btree (created_at, uuid)")
+      ActiveRecord::Base.connection.execute("CREATE INDEX IF NOT EXISTS index_#{table.to_s}_on_modified_at_and_uuid ON #{table.to_s} USING btree (modified_at desc, uuid desc)")
     end
   end
 
   def down
     @@idxtables.each do |table|
       ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_created_at")
-      ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_created_at_uuid")
+      ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_created_at_and_uuid")
       ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_modified_at")
       ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_modified_at_uuid")
+      ActiveRecord::Base.connection.execute("DROP INDEX IF EXISTS index_#{table.to_s}_on_modified_at_and_uuid")
 
-      ActiveRecord::Base.connection.execute("CREATE INDEX index_#{table.to_s}_on_created_at ON #{table.to_s} USING btree  (created_at)")
-      ActiveRecord::Base.connection.execute("CREATE INDEX index_#{table.to_s}_on_modified_at_uuid ON #{table.to_s} USING btree (modified_at desc, uuid asc)")
+      ActiveRecord::Base.connection.execute("CREATE INDEX IF NOT EXISTS index_#{table.to_s}_on_created_at_and_uuid ON #{table.to_s} USING btree (created_at, uuid)")
+      ActiveRecord::Base.connection.execute("CREATE INDEX IF NOT EXISTS index_#{table.to_s}_on_modified_at_uuid ON #{table.to_s} USING btree (modified_at desc, uuid asc)")
     end
   end
 end
index 9c08b81e0e41d7cc6832eca094915052ad3f20bc..8cb27ab4df6f24cc99ee0801c810f5b0568ecdd2 100644 (file)
@@ -1940,10 +1940,10 @@ CREATE INDEX index_collections_on_is_trashed ON public.collections USING btree (
 
 
 --
--- Name: index_collections_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+-- Name: index_collections_on_modified_at_and_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE INDEX index_collections_on_modified_at_uuid ON public.collections USING btree (modified_at DESC, uuid DESC);
+CREATE INDEX index_collections_on_modified_at_and_uuid ON public.collections USING btree (modified_at DESC, uuid DESC);
 
 
 --
@@ -1988,6 +1988,13 @@ CREATE UNIQUE INDEX index_collections_on_uuid ON public.collections USING btree
 CREATE INDEX index_container_requests_on_container_uuid ON public.container_requests USING btree (container_uuid);
 
 
+--
+-- Name: index_container_requests_on_created_at_and_uuid; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_container_requests_on_created_at_and_uuid ON public.container_requests USING btree (created_at, uuid);
+
+
 --
 -- Name: index_container_requests_on_created_at_uuid; Type: INDEX; Schema: public; Owner: -
 --
@@ -1996,10 +2003,10 @@ CREATE INDEX index_container_requests_on_created_at_uuid ON public.container_req
 
 
 --
--- Name: index_container_requests_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+-- Name: index_container_requests_on_modified_at_and_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE INDEX index_container_requests_on_modified_at_uuid ON public.container_requests USING btree (modified_at DESC, uuid DESC);
+CREATE INDEX index_container_requests_on_modified_at_and_uuid ON public.container_requests USING btree (modified_at DESC, uuid DESC);
 
 
 --
@@ -2136,10 +2143,10 @@ CREATE INDEX index_groups_on_is_trashed ON public.groups USING btree (is_trashed
 
 
 --
--- Name: index_groups_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+-- Name: index_groups_on_modified_at_and_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE INDEX index_groups_on_modified_at_uuid ON public.groups USING btree (modified_at DESC, uuid DESC);
+CREATE INDEX index_groups_on_modified_at_and_uuid ON public.groups USING btree (modified_at DESC, uuid DESC);
 
 
 --
@@ -2388,10 +2395,10 @@ CREATE INDEX index_links_on_head_uuid ON public.links USING btree (head_uuid);
 
 
 --
--- Name: index_links_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+-- Name: index_links_on_modified_at_and_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE INDEX index_links_on_modified_at_uuid ON public.links USING btree (modified_at DESC, uuid DESC);
+CREATE INDEX index_links_on_modified_at_and_uuid ON public.links USING btree (modified_at DESC, uuid DESC);
 
 
 --
@@ -2458,10 +2465,10 @@ CREATE INDEX index_logs_on_event_type ON public.logs USING btree (event_type);
 
 
 --
--- Name: index_logs_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+-- Name: index_logs_on_modified_at_and_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE INDEX index_logs_on_modified_at_uuid ON public.logs USING btree (modified_at DESC, uuid DESC);
+CREATE INDEX index_logs_on_modified_at_and_uuid ON public.logs USING btree (modified_at DESC, uuid DESC);
 
 
 --
@@ -2611,6 +2618,13 @@ CREATE INDEX index_pipeline_templates_on_owner_uuid ON public.pipeline_templates
 CREATE UNIQUE INDEX index_pipeline_templates_on_uuid ON public.pipeline_templates USING btree (uuid);
 
 
+--
+-- Name: index_repositories_on_created_at_and_uuid; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_repositories_on_created_at_and_uuid ON public.repositories USING btree (created_at, uuid);
+
+
 --
 -- Name: index_repositories_on_created_at_uuid; Type: INDEX; Schema: public; Owner: -
 --
@@ -2619,10 +2633,10 @@ CREATE INDEX index_repositories_on_created_at_uuid ON public.repositories USING
 
 
 --
--- Name: index_repositories_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+-- Name: index_repositories_on_modified_at_and_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE INDEX index_repositories_on_modified_at_uuid ON public.repositories USING btree (modified_at DESC, uuid DESC);
+CREATE INDEX index_repositories_on_modified_at_and_uuid ON public.repositories USING btree (modified_at DESC, uuid DESC);
 
 
 --
@@ -2724,10 +2738,10 @@ CREATE UNIQUE INDEX index_users_on_identity_url ON public.users USING btree (ide
 
 
 --
--- Name: index_users_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+-- Name: index_users_on_modified_at_and_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE INDEX index_users_on_modified_at_uuid ON public.users USING btree (modified_at DESC, uuid DESC);
+CREATE INDEX index_users_on_modified_at_and_uuid ON public.users USING btree (modified_at DESC, uuid DESC);
 
 
 --
@@ -2751,6 +2765,13 @@ CREATE UNIQUE INDEX index_users_on_username ON public.users USING btree (usernam
 CREATE UNIQUE INDEX index_users_on_uuid ON public.users USING btree (uuid);
 
 
+--
+-- Name: index_virtual_machines_on_created_at_and_uuid; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_virtual_machines_on_created_at_and_uuid ON public.virtual_machines USING btree (created_at, uuid);
+
+
 --
 -- Name: index_virtual_machines_on_created_at_uuid; Type: INDEX; Schema: public; Owner: -
 --
@@ -2766,10 +2787,10 @@ CREATE INDEX index_virtual_machines_on_hostname ON public.virtual_machines USING
 
 
 --
--- Name: index_virtual_machines_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+-- Name: index_virtual_machines_on_modified_at_and_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE INDEX index_virtual_machines_on_modified_at_uuid ON public.virtual_machines USING btree (modified_at DESC, uuid DESC);
+CREATE INDEX index_virtual_machines_on_modified_at_and_uuid ON public.virtual_machines USING btree (modified_at DESC, uuid DESC);
 
 
 --
@@ -2786,6 +2807,13 @@ CREATE INDEX index_virtual_machines_on_owner_uuid ON public.virtual_machines USI
 CREATE UNIQUE INDEX index_virtual_machines_on_uuid ON public.virtual_machines USING btree (uuid);
 
 
+--
+-- Name: index_workflows_on_created_at_and_uuid; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_workflows_on_created_at_and_uuid ON public.workflows USING btree (created_at, uuid);
+
+
 --
 -- Name: index_workflows_on_created_at_uuid; Type: INDEX; Schema: public; Owner: -
 --
@@ -2794,10 +2822,10 @@ CREATE INDEX index_workflows_on_created_at_uuid ON public.workflows USING btree
 
 
 --
--- Name: index_workflows_on_modified_at_uuid; Type: INDEX; Schema: public; Owner: -
+-- Name: index_workflows_on_modified_at_and_uuid; Type: INDEX; Schema: public; Owner: -
 --
 
-CREATE INDEX index_workflows_on_modified_at_uuid ON public.workflows USING btree (modified_at DESC, uuid DESC);
+CREATE INDEX index_workflows_on_modified_at_and_uuid ON public.workflows USING btree (modified_at DESC, uuid DESC);
 
 
 --