Comment 10 for bug 742916

Revision history for this message
Robert Collins (lifeless) wrote :

Aaron's suggestion was:
' We could find the revno of the newest revision older than $DATE and then retrieve all BranchRevisions with a higher revno.'

So, that revno from first principles is:
SELECT max(branchrevision.sequence) as revno
  FROM Revision JOIN BranchRevision ON BranchRevision.revision = Revision.id
  WHERE BranchRevision.branch = 492361 AND branchrevision.sequence is not null and Revision.revision_date < '2009-08-10 21:56:30.623339+00:00';

This is still expensive - note the estimated cost (and slow hot performance - nearly 1 second).
 explain analyze SELECT max(branchrevision.sequence) as revno
  FROM Revision JOIN BranchRevision ON BranchRevision.revision = Revision.id
  WHERE BranchRevision.branch = 492361 AND Revision.revision_date < '2009-08-10 21:56:30.623339+00:00';
                                                                                   QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate (cost=176644.63..176644.64 rows=1 width=4) (actual time=906.960..906.961 rows=1 loops=1)
   -> Nested Loop (cost=0.00..176591.63 rows=21199 width=4) (actual time=0.068..891.013 rows=65107 loops=1)
         -> Index Scan using revisionnumber_branch_sequence_unique on branchrevision (cost=0.00..29518.34 rows=21199 width=8) (actual time=0.042..66.305 rows=105756 loops=1)
               Index Cond: (branch = 492361)
         -> Index Scan using changeset_pkey on revision (cost=0.00..6.93 rows=1 width=4) (actual time=0.007..0.007 rows=1 loops=105756)
               Index Cond: (revision.id = branchrevision.revision)
               Filter: (revision.revision_date < '2009-08-10 21:56:30.623339'::timestamp without time zone)
 Total runtime: 907.041 ms

you can see the plan is nearly identical - all