]> xenbits.xensource.com Git - osstest.git/commitdiff
sg-report-host-history: Do the main query per host
authorIan Jackson <ian.jackson@eu.citrix.com>
Fri, 24 Jul 2020 15:11:49 +0000 (16:11 +0100)
committerIan Jackson <ian.jackson@eu.citrix.com>
Thu, 6 Aug 2020 09:23:19 +0000 (10:23 +0100)
In f6001d628c3b3fd42b10cd15351981a04bc02572 we combined these
queries into one:
  sg-report-host-history: Aggregate runvars query for all hosts

Now that we have an index, there is a faster way for the db to do this
query: via that index.  But it doesn't like to do that if be aggregate
the queries.  Experimentally, doing this query separately once per
host is significantly faster.

Also, later, it will allow us to parallelise this work.

So, we undo that.  (Not by reverting, though.)

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
v2: Use proper \ escaping for underscores in LIKE

schema/runvars-host-index.sql
sg-report-host-history

index 222a0a30c19a460b5697e82ed38950dc85d6be49..6a3ef3770132ccbee87ea717c39284fbe79e86c2 100644 (file)
@@ -1,4 +1,4 @@
--- ##OSSTEST## 009 Preparatory
+-- ##OSSTEST## 009 Needed
 --
 -- This index helps sg-report-host-history find relevant flights.
 
index 1c2d19aea31dbf73062b778143c10c3efd66c35b..15866ab676f09b85eb3748786716741391118ecf 100755 (executable)
@@ -165,34 +165,25 @@ sub jobquery ($$$) {
 our %hosts;
 
 sub mainquery () {
-    our $valcond = join " OR ", map { "val = ?" } keys %hosts;
-    our @params = keys %hosts;
-
     our $runvarq //= db_prepare(<<END);
-       SELECT flight, job, name, val, status
+       SELECT flight, job, name, status
          FROM runvars
           JOIN jobs USING (flight, job)
-        WHERE $namecond
-          AND ($valcond)
+        WHERE (name = 'host' OR name LIKE '%\_host')
+          AND val = ?
           AND $flightcond
            AND $restrictflight_cond
            AND flight > ?
         ORDER BY flight DESC
-        LIMIT ($limit * 3 + 100) * ?
+         LIMIT $limit * 2
 END
+    foreach my $host (sort keys %hosts) {
+       print DEBUG "MAINQUERY $host...\n";
+       $runvarq->execute($host, $minflight);
 
-    push @params, $minflight;
-    push @params, scalar keys %hosts;
-
-    print DEBUG "MAINQUERY...\n";
-    $runvarq->execute(@params);
-
-    print DEBUG "FIRST PASS\n";
-    while (my $jr= $runvarq->fetchrow_hashref()) {
-       print DEBUG " $jr->{flight}.$jr->{job} ";
-       push @{ $hosts{$jr->{val}} }, $jr;
+       $hosts{$host} = $runvarq->fetchall_arrayref({});
+       print DEBUG "MAINQUERY $host got ".(scalar @{ $hosts{$host} })."\n";
     }
-    print DEBUG "\n";
 }
 
 sub reporthost ($) {