[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] [metrics-db/master] Count consensuses per day more efficiently.



commit 4d782e3a874f6c9fe8f8a74b53a771c7f7ca2bf9
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Tue Jan 18 11:54:44 2011 +0100

    Count consensuses per day more efficiently.
    
    No need to look at thousands of status entries when we can look at the
    consensuses directly.
---
 db/tordir.sql |   10 ++++------
 1 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/db/tordir.sql b/db/tordir.sql
index 689a4b4..7af0093 100644
--- a/db/tordir.sql
+++ b/db/tordir.sql
@@ -255,12 +255,10 @@ RETURNS INTEGER AS $$
     WHERE date IN (SELECT date FROM updates);
     INSERT INTO relay_statuses_per_day (date, count)
     SELECT DATE(validafter) AS date, COUNT(*) AS count
-    FROM (SELECT DISTINCT validafter
-          FROM statusentry
-          WHERE DATE(validafter) >= (SELECT MIN(date) FROM updates)
-          AND DATE(validafter) <= (SELECT MAX(date) FROM updates)
-          AND DATE(validafter) IN (SELECT date FROM updates))
-          distinct_consensuses
+    FROM consensus
+    WHERE DATE(validafter) >= (SELECT MIN(date) FROM updates)
+    AND DATE(validafter) <= (SELECT MAX(date) FROM updates)
+    AND DATE(validafter) IN (SELECT date FROM updates)
     GROUP BY DATE(validafter);
     RETURN 1;
     END;