A variant that examines slightly less rows
explain analyze SELECT DISTINCT LibraryFileContent.datecreated, LibraryFileContent.filesize, LibraryFileContent.id, LibraryFileContent.md5, LibraryFileContent.sha1 FROM BinaryPackageFile, BinaryPackagePublishingHistory, LibraryFileAlias, LibraryFileContent WHERE BinaryPackagePublishingHistory.archive = 14516 AND BinaryPackagePublishingHistory.dateremoved IS NULL AND BinaryPackagePublishingHistory.binarypackagerelease = BinaryPackageFile.binarypackagerelease AND BinaryPackageFile.libraryfile = LibraryFileAlias.id AND LibraryFileAlias.content = LibraryFileContent.id AND BinaryPackagePublishingHistory.status IN (2); QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- HashAggregate (cost=6614.28..6617.22 rows=294 width=94) (actual time=61.875..62.380 rows=596 loops=1) -> Nested Loop (cost=0.00..6610.60 rows=294 width=94) (actual time=0.094..58.355 rows=1642 loops=1) -> Nested Loop (cost=0.00..6055.27 rows=378 width=4) (actual time=0.076..43.243 rows=1642 loops=1) -> Nested Loop (cost=0.00..5274.09 rows=378 width=4) (actual time=0.057..27.212 rows=1642 loops=1) -> Index Scan using securebinarypackagepublishinghistory__archive__status__idx on binarypackagepublishinghistory (cost=0.00..2735.80 rows=378 width=4) (actual time=0.036..13.610 rows=1642 loops=1) Index Cond: ((archive = 14516) AND (status = 2)) Filter: (dateremoved IS NULL) -> Index Scan using binarypackagefile_binarypackage_idx on binarypackagefile (cost=0.00..6.70 rows=1 width=8) (actual time=0.006..0.007 rows=1 loops=1642) Index Cond: (binarypackagefile.binarypackagerelease = binarypackagepublishinghistory.binarypackagerelease) -> Index Scan using libraryfilealias_pkey on libraryfilealias (cost=0.00..2.05 rows=1 width=8) (actual time=0.008..0.008 rows=1 loops=1642) Index Cond: (libraryfilealias.id = binarypackagefile.libraryfile) -> Index Scan using libraryfilecontent_pkey on libraryfilecontent (cost=0.00..1.46 rows=1 width=94) (actual time=0.007..0.007 rows=1 loops=1642) Index Cond: (libraryfilecontent.id = libraryfilealias.content) Total runtime: 62.705 ms
A variant that examines slightly less rows
explain analyze SELECT DISTINCT LibraryFileCont ent.datecreated ,
LibraryFileCo ntent.filesize,
LibraryFileCo ntent.id,
LibraryFileCo ntent.md5,
LibraryFileCo ntent.sha1 agePublishingHi story, eAlias, eContent blishingHistory .archive = 14516 blishingHistory .dateremoved IS NULL blishingHistory .binarypackager elease = BinaryPackageFi le.binarypackag erelease le.libraryfile = LibraryFileAlias.id s.content = LibraryFileCont ent.id AND BinaryPackagePu blishingHistory .status IN (2);
QUERY PLAN ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- --- 28..6617. 22 rows=294 width=94) (actual time=61.875..62.380 rows=596 loops=1)
-> Index Scan using securebinarypac kagepublishingh istory_ _archive_ _status_ _idx on binarypackagepu blishinghistory (cost=0.00..2735.80 rows=378 width=4) (actual time=0.036..13.610 rows=1642 loops=1)
Index Cond: ((archive = 14516) AND (status = 2))
Filter: (dateremoved IS NULL)
-> Index Scan using binarypackagefi le_binarypackag e_idx on binarypackagefile (cost=0.00..6.70 rows=1 width=8) (actual time=0.006..0.007 rows=1 loops=1642)
Index Cond: (binarypackagef ile.binarypacka gerelease = binarypackagepu blishinghistory .binarypackager elease) s_pkey on libraryfilealias (cost=0.00..2.05 rows=1 width=8) (actual time=0.008..0.008 rows=1 loops=1642)
Index Cond: (libraryfileali as.id = binarypackagefi le.libraryfile) ent_pkey on libraryfilecontent (cost=0.00..1.46 rows=1 width=94) (actual time=0.007..0.007 rows=1 loops=1642)
Index Cond: (libraryfilecon tent.id = libraryfilealia s.content)
FROM BinaryPackageFile,
BinaryPack
LibraryFil
LibraryFil
WHERE BinaryPackagePu
AND BinaryPackagePu
AND BinaryPackagePu
AND BinaryPackageFi
AND LibraryFileAlia
-------
HashAggregate (cost=6614.
-> Nested Loop (cost=0.00..6610.60 rows=294 width=94) (actual time=0.094..58.355 rows=1642 loops=1)
-> Nested Loop (cost=0.00..6055.27 rows=378 width=4) (actual time=0.076..43.243 rows=1642 loops=1)
-> Nested Loop (cost=0.00..5274.09 rows=378 width=4) (actual time=0.057..27.212 rows=1642 loops=1)
-> Index Scan using libraryfilealia
-> Index Scan using libraryfilecont
Total runtime: 62.705 ms