Ian Booth has proposed merging 
lp:~wallyworld/launchpad/person-bugs-timeout-897923 into lp:launchpad.

Commit message:
Remove an unnecessary and costly distinct from a subquery used to search 
commented bugs.

Requested reviews:
  Ian Booth (wallyworld)
Related bugs:
  Bug #897923 in Launchpad itself: "Person:+bugs timeout"
  https://bugs.launchpad.net/launchpad/+bug/897923

For more details, see:
https://code.launchpad.net/~wallyworld/launchpad/person-bugs-timeout-897923/+merge/130280

The core issue was that the subselect used to get the bug ids of the relevant 
bug messages was using distinct.

eg

SELECT BugTaskFlat.bugtask FROM BugTaskFlat LEFT JOIN Product ON 
BugTaskFlat.product = Product.id AND Product.active WHERE BugTaskFlat.status IN 
(25, 10, 20, 21, 22, 13, 14) AND BugTaskFlat.duplicateof IS NULL AND 
(BugTaskFlat.product IS NULL OR Product.active = True) AND BugTaskFlat.bug IN 
(SELECT DISTINCT BugMessage.bug FROM BugMessage WHERE BugMessage.index > 0 AND 
BugMessage.owner = 1) AND True ORDER BY BugTaskFlat.importance DESC, 
BugTaskFlat.bugtask LIMIT 8 OFFSET 0

The DISTINCT messed up Postgres, causing it to sort the potentially large list 
of bugs and then filter, rather than the other way around.

I use a feature flag to (by default) remove the DISTINCT.
-- 
https://code.launchpad.net/~wallyworld/launchpad/person-bugs-timeout-897923/+merge/130280
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.
=== modified file 'lib/lp/bugs/model/bugtasksearch.py'
--- lib/lp/bugs/model/bugtasksearch.py	2012-10-01 03:40:51 +0000
+++ lib/lp/bugs/model/bugtasksearch.py	2012-10-18 04:30:40 +0000
@@ -92,6 +92,7 @@
     get_where_for_reference,
     Unnest,
     )
+from lp.services.features import getFeatureFlag
 from lp.services.propertycache import get_property_cache
 from lp.services.searchbuilder import (
     all,
@@ -623,13 +624,15 @@
         extra_clauses.append(BugTaskFlat.bug_owner == params.bug_reporter)
 
     if params.bug_commenter:
+        use_distinct = bool(getFeatureFlag(
+            'bug_comment_search.use_distinct.enabled'))
         extra_clauses.append(
             BugTaskFlat.bug_id.is_in(Select(
                 BugMessage.bugID, tables=[BugMessage],
                 where=And(
                     BugMessage.index > 0,
                     BugMessage.owner == params.bug_commenter),
-                distinct=True)))
+                distinct=use_distinct)))
 
     if params.affects_me:
         params.affected_user = params.user

=== modified file 'lib/lp/services/features/flags.py'
--- lib/lp/services/features/flags.py	2012-10-12 03:11:38 +0000
+++ lib/lp/services/features/flags.py	2012-10-18 04:30:40 +0000
@@ -214,6 +214,13 @@
      '',
      '',
      ''),
+    ('bug_comment_search.use_distinct.enabled',
+     'boolean',
+     ('If true, the bug message sub query for finding commented bugs '
+      'uses DISTINCT.'),
+     '',
+     '',
+     ''),
     ('registry.upcoming_work_view.enabled',
      'boolean',
      ('If true, the new upcoming work view of teams is available.'),

_______________________________________________
Mailing list: https://launchpad.net/~launchpad-reviewers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~launchpad-reviewers
More help   : https://help.launchpad.net/ListHelp

Reply via email to