@@ -1,4 +1,4 @@
+-- ##OSSTEST## 006 Needed
--
-- This index helps sg-report-flight find if a test ever passed.
@@ -849,10 +849,20 @@ sub justifyfailures ($;$) {
my @failures= values %{ $fi->{Failures} };
+ # In psql 9.6 this WITH clause makes postgresql do the steps query
+ # first. This is good because if this test never passed we can
+ # determine that really quickly using the new index, without
+ # having to scan the flights table. (If the test passed we will
+ # probably not have to look at many flights to find one, so in
+ # that case this is not much worse.)
my $anypassq= <<END;
- SELECT * FROM flights JOIN steps USING (flight)
+ WITH s AS
+ (
+ SELECT * FROM steps
+ WHERE job=? and testid=? and status='pass'
+ )
+ SELECT * FROM flights JOIN s USING (flight)
WHERE $branches_cond_q
- AND job=? and testid=? and status='pass'
AND $blessingscond
LIMIT 1
END