From: Ian Jackson Subject: [OSSTEST PATCH 2/6] sg-report-job-history: Avoid full runvars table scan (!) Date: Fri, 1 May 2015 16:02:44 +0100 Message-ID: <1430492568-1761-3-git-send-email-ian.jackson@eu.citrix.com> References: <21827.30808.198577.574772@mariner.uk.xensource.com> <1430492568-1761-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YoCTG-0005rz-Fi for xen-devel@lists.xenproject.org; Fri, 01 May 2015 15:03:18 +0000 In-Reply-To: <1430492568-1761-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Ian Jackson , Ian Campbell List-Id: xen-devel@lists.xenproject.org sg-report-job-history wnats to know the potential names of runvars relating to hosts. To do this it tries to find a list of distinct runvar names which exist in the flights it's processing. However, it fails to limit the runvar query appropriately, and as a result postgresql must scan almost the complete runvars table to produce an answer. This is very slow if the table is bigger than the database server's RAM. Fix this by limiting the runvars table query to relevant flights. Specifically: * Break the `100' from the LIMIT clause on the flights search into a local variable $limit. * Break the bulk of the flights search sql statement text into a local variable $fromstuff. * In the runvars statement, add a condition on flights which uses LIMIT and OFFSET, based on results of the the flights query. Signed-off-by: Ian Jackson --- sg-report-job-history | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sg-report-job-history b/sg-report-job-history index e7052a3..d59717f 100755 --- a/sg-report-job-history +++ b/sg-report-job-history @@ -163,12 +163,17 @@ sub processjobbranch ($$) { END push @params, $bra; } - my $flightsq= $dbh_tests->prepare(<prepare(<execute(@params); @@ -177,9 +182,13 @@ END FROM runvars JOIN flights USING (flight) WHERE ($cond) + AND flight >= ( + SELECT flight $fromstuff + LIMIT 1 OFFSET $offset + ) ORDER BY name; END - $hostsq->execute(@params); + $hostsq->execute(@params, @params); my @hostvarcols; while (my ($hostvar) = $hostsq->fetchrow_array()) { next unless $hostvar =~ m/(^|_)host$/; -- 1.7.10.4