From 8c5fbfc20a40a4a74b3117f0470b869323b2e096 Mon Sep 17 00:00:00 2001
From: Duncan Meacher <duncan.meacher@ligo.org>
Date: Wed, 23 Jan 2019 01:11:49 -0600
Subject: [PATCH] simplify_and_cluster.sql: Fix to speed up run time

---
 gstlal-inspiral/share/simplify_and_cluster.sql | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/gstlal-inspiral/share/simplify_and_cluster.sql b/gstlal-inspiral/share/simplify_and_cluster.sql
index 7bec419120..65f11c900b 100644
--- a/gstlal-inspiral/share/simplify_and_cluster.sql
+++ b/gstlal-inspiral/share/simplify_and_cluster.sql
@@ -35,6 +35,7 @@ CREATE TEMPORARY TABLE _idmap_ AS
 		old.process_id;
 DROP INDEX tmpindex;
 CREATE INDEX tmpindex ON _idmap_ (old);
+CREATE INDEX tmpindex2 ON _idmap_ (new, old);
 
 UPDATE coinc_event SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
 UPDATE segment SET process_id = (SELECT new FROM _idmap_ WHERE old == process_id);
@@ -47,6 +48,7 @@ DELETE FROM process WHERE process_id IN (SELECT old FROM _idmap_ WHERE old != ne
 DELETE FROM process_params WHERE process_id NOT IN (SELECT process_id FROM process);
 
 DROP INDEX tmpindex;
+DROP INDEX tmpindex2;
 DROP TABLE _idmap_;
 
 --
@@ -66,11 +68,13 @@ CREATE TEMPORARY TABLE _idmap_ AS
 	GROUP BY
 		old.coinc_def_id;
 CREATE INDEX tmpindex ON _idmap_ (old);
+CREATE INDEX tmpindex2 ON _idmap_ (new, old);
 
 UPDATE coinc_event SET coinc_def_id = (SELECT new FROM _idmap_ WHERE old == coinc_def_id);
 DELETE FROM coinc_definer WHERE coinc_def_id IN (SELECT old FROM _idmap_ WHERE old != new);
 
 DROP INDEX tmpindex;
+DROP INDEX tmpindex2;
 DROP TABLE _idmap_;
 
 --
@@ -108,6 +112,8 @@ DROP TABLE _idmap_;
 -- references to their IDs in other tables
 --
 
+CREATE INDEX tmpindex ON segment(segment_def_id, start_time, start_time_ns, end_time, end_time_ns);
+
 DELETE FROM
 	segment
 WHERE
@@ -125,6 +131,7 @@ WHERE
 			AND other.segment_id < segment.segment_id
 	);
 
+DROP INDEX tmpindex;
 --
 -- time_slide clean up
 --
-- 
GitLab