From 52e43af4fa157384912f39664241c596bb5ab278 Mon Sep 17 00:00:00 2001
From: Martijn Vermaat <martijn@vermaat.name>
Date: Tue, 19 Jul 2011 11:59:10 +0000
Subject: [PATCH] Optimization for batch scheduler.

Getting the next batch queue entry to process was slow with a large database
due to the getFromQueue select query. This query is now replaced by one that
can make use of an index on the BatchQueue table.


git-svn-id: https://humgenprojects.lumc.nl/svn/mutalyzer/branches/refactor-mutalyzer-branch@296 eb6bd6ab-9ccd-42b9-aceb-e2899b4a52f1
---
 mutalyzer/Db.py | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/mutalyzer/Db.py b/mutalyzer/Db.py
index f8a3de04..6a40eba8 100644
--- a/mutalyzer/Db.py
+++ b/mutalyzer/Db.py
@@ -1491,12 +1491,19 @@ class Batch(Db) :
         @rtype: triple
         """
 
+        # To optimize this query, make sure to have two indices on the
+        # table:
+        # - UNIQUE KEY (QueueID)
+        # - KEY (JobID, QueueID)
         statement = """
             SELECT QueueID, Input, Flags
-              FROM BatchQueue
-              WHERE JobID = %s
-              ORDER BY QueueID
-              LIMIT 1;
+            FROM BatchQueue
+            WHERE QueueID = (
+                SELECT QueueID
+                FROM BatchQueue
+                GROUP BY JobID
+                HAVING JobID = %s
+            );
         """, jobID
 
         results = self.query(statement)
-- 
GitLab