Merge lp:~deryck/launchpad/max-heat-timeout-again-618403 into lp:launchpad

Proposed by Deryck Hodge
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 11494
Proposed branch: lp:~deryck/launchpad/max-heat-timeout-again-618403
Merge into: lp:launchpad
Diff against target: 59 lines (+24/-12)
1 file modified
lib/lp/bugs/model/bugtarget.py (+24/-12)
To merge this branch: bzr merge lp:~deryck/launchpad/max-heat-timeout-again-618403
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Launchpad code reviewers Pending
Review via email: mp+34498@code.launchpad.net

Commit message

Find a compromise query which works for debian and ubuntu heat calculations with tolerable performance.

Description of the change

Round and round we go. Is it spelled MAX(Bug.heat) or ORDER BY
Bug.heat DESC LIMIT 1?

Drum roll......

ORDER BY/LIMIT 1 wins in a taste test challenge (with an occassional
FOO IS NOT NULL thrown in).

lifeless will know what I mean and stands ready to approve.

Cheers,
deryck

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

\o/

may want to factor out the common bits of those queries in future.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/model/bugtarget.py'
2--- lib/lp/bugs/model/bugtarget.py 2010-08-22 18:31:30 +0000
3+++ lib/lp/bugs/model/bugtarget.py 2010-09-02 22:12:51 +0000
4@@ -271,32 +271,44 @@
5 # recalculating max_heat.
6 return
7
8+ # XXX: deryck The queries here are a source of pain and have
9+ # been changed a couple times looking for the best
10+ # performaning version. Use caution and have EXPLAIN ANALYZE
11+ # data ready when changing these.
12 if IDistribution.providedBy(self):
13- sql = ["""SELECT MAX(Bug.heat)
14+ sql = ["""SELECT Bug.heat
15 FROM Bug, Bugtask
16 WHERE Bugtask.bug = Bug.id
17- AND Bugtask.distribution = %s""" % sqlvalues(self),
18- """SELECT MAX(Bug.heat)
19+ AND Bugtask.distribution = %s
20+ ORDER BY Bug.heat DESC LIMIT 1""" % sqlvalues(self),
21+ """SELECT Bug.heat
22 FROM Bug, Bugtask, DistroSeries
23 WHERE Bugtask.bug = Bug.id
24 AND Bugtask.distroseries = DistroSeries.id
25- AND DistroSeries.distribution = %s""" % sqlvalues(self)]
26+ AND Bugtask.distroseries IS NOT NULL
27+ AND DistroSeries.distribution = %s
28+ ORDER BY Bug.heat DESC LIMIT 1""" % sqlvalues(self)]
29 elif IProduct.providedBy(self):
30- sql = ["""SELECT MAX(Bug.heat)
31+ sql = ["""SELECT Bug.heat
32 FROM Bug, Bugtask
33 WHERE Bugtask.bug = Bug.id
34- AND Bugtask.product = %s""" % sqlvalues(self),
35- """SELECT MAX(Bug.heat)
36+ AND Bugtask.product = %s
37+ ORDER BY Bug.heat DESC LIMIT 1""" % sqlvalues(self),
38+ """SELECT Bug.heat
39 FROM Bug, Bugtask, ProductSeries
40 WHERE Bugtask.bug = Bug.id
41+ AND Bugtask.productseries IS NOT NULL
42 AND Bugtask.productseries = ProductSeries.id
43- AND ProductSeries.product = %s""" % sqlvalues(self)]
44+ AND ProductSeries.product = %s
45+ ORDER BY Bug.heat DESC LIMIT 1""" % sqlvalues(self)]
46 elif IProjectGroup.providedBy(self):
47- sql = ["""SELECT MAX(heat)
48+ sql = ["""SELECT heat
49 FROM Bug, Bugtask, Product
50- WHERE Bugtask.bug = Bug.id AND
51- Bugtask.product = Product.id AND
52- Product.project = %s""" % sqlvalues(self)]
53+ WHERE Bugtask.bug = Bug.id
54+ AND Bugtask.product = Product.id
55+ AND Product.project IS NOT NULL
56+ AND Product.project = %s
57+ ORDER BY Bug.heat DESC LIMIT 1""" % sqlvalues(self)]
58 else:
59 raise NotImplementedError
60