Merge ~cjwatson/launchpad:optimize-latest-uploads into launchpad:master
Proposed by
Colin Watson
Status: | Merged |
---|---|
Approved by: | Colin Watson |
Approved revision: | 997e14ca8387b301861d9e5a2e772d5364e81ee8 |
Merge reported by: | Otto Co-Pilot |
Merged at revision: | not available |
Proposed branch: | ~cjwatson/launchpad:optimize-latest-uploads |
Merge into: | launchpad:master |
Diff against target: |
93 lines (+34/-18) 1 file modified
lib/lp/registry/model/distroseries.py (+34/-18) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Cristian Gonzalez (community) | Approve | ||
Review via email: mp+403735@code.launchpad.net |
Commit message
Make DistroSeries.
Description of the change
Unassisted, PostgreSQL's planner apparently decides to do an index scan on `PackageUpload`'s primary key, which is very slow. Use a CTE to force it to use the more appropriate index on `PackageUpload (archive, distroseries, status)`.
To post a comment you must log in.
Old query plan (just `EXPLAIN` as it was far too slow for `ANALYZE`):
``` ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ----- 14..1614196. 46 rows=43728 width=1288) 72..1595163. 07 rows=43728 width=1268) 30..1576129. 69 rows=43728 width=1268)
-> Nested Loop (cost=0. 87..1540544. 13 rows=43728 width=8)
- > Index Scan Backward using distroreleasequ eue_pkey on packageupload (cost=0. 44..1356507. 63 rows=173502 width=4)
Filter: ((archive = ANY ('{1,534} '::integer[ ])) AND (status = 3) AND (distroseries = 108))
- > Index Scan using packageuploadso urce__packageup load__key on packageuploadsource (cost=0.43..1.06 rows=1 width=8)
Index Cond: (packageupload = packageupload.id)
-> Index Scan using sourcepackagere lease_pkey on sourcepackagere lease (cost=0.43..0.81 rows=1 width=1264)
Index Cond: (id = packageuploadso urce.sourcepack agerelease) me_pkey on sourcepackagename (cost=0.42..0.44 rows=1 width=4)
Index Cond: (id = sourcepackagere lease.sourcepac kagename) me_pkey on sourcepackagename _prejoin1 (cost=0.42..0.44 rows=1 width=20)
Index Cond: (sourcepackager elease. sourcepackagena me = id)
QUERY PLAN
-------
Limit (cost=2.14..186.71 rows=5 width=1288)
-> Nested Loop Left Join (cost=2.
-> Nested Loop (cost=1.
-> Nested Loop (cost=1.
-> Index Only Scan using sourcepackagena
-> Index Scan using sourcepackagena
(15 rows)
```
New query plan:
``` lease.* , "_prejoin1".id, "_prejoin1".name FROM RelevantUpload, PackageUploadSo urce, SourcePackageName, SourcePackageRe lease LEFT JOIN SourcePackageName AS "_prejoin1" ON SourcePackageRe lease.sourcepac kagename = "_prejoin1".id WHERE sourcepackagere lease.id= packageuploadso urce.sourcepack agerelease AND sourcepackagere lease.sourcepac kagename= sourcepackagena me.id AND packageuploadso urce.packageupl oad=relevantupl oad.id ORDER BY relevantupload.id DESC LIMIT 5;
QUERY PLAN ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ----- 38..237919. 24 rows=5 width=1483) (actual time=236. 269..905. 036 rows=5 loops=1) 68..219334. 98 rows=173502 width=4) (actual time=22.161..86.424 rows=139208 loops=1) '::integer[ ])) AND (distroseries = 108) AND (status = 3))
launchpad_staging=> EXPLAIN (ANALYZE, BUFFERS) WITH RelevantUpload AS (SELECT id FROM PackageUpload WHERE status = 3 AND distroseries = 108 AND archive IN (1, 534)) SELECT SourcePackageRe
-------
Limit (cost=237905.
Buffers: shared hit=80357
CTE relevantupload
-> Bitmap Heap Scan on packageupload (cost=3415.
Recheck Cond: ((archive = ANY ('{1,534}
Heap Blocks:...