Closed Bug 425618 Opened 16 years ago Closed 12 years ago

Canned activity searches are slow

Categories

(bugzilla.mozilla.org :: General, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: bbaetz, Unassigned)

References

()

Details

Attachments

(2 files)

this is bmo specific because this feature is bmo specific, but that code just copied from Bug.pm. I also need some timings from justdave, so.... Any fix is likely to be upstream, or at least should be applied to the duplicate code

This query is slow - 8 second from 2008-03-01 to first output, and 33 seconds from 2008-01-01 (time wget, ctrl-C after some output). Its 90 seconds w/o a date limit.

Using me as the user its 2 seconds for this month (2 bugs changed this month), so that the baseline.

Dave, can you please do an explain and get me the query times for:

SELECT count(bugs_activity.bug_id) FROM bugs_activity
  LEFT JOIN attachments ON attachments.attach_id = bugs_activity.attach_id
  LEFT JOIN fielddefs ON bugs_activity.fieldid = fielddefs.id
 INNER JOIN profiles ON profiles.userid = bugs_activity.who
     WHERE bugs_activity.who = 'reed@reedloden.com'
       AND bugs_activity.bug_when >= '2008-03-01 00:00:00' AND bugs_activity.bug_when <= '2008-03-27 23:59:59'

(Run that twice in a row, just to prime up the caches for the first time)

SELECT count(bugs_activity.bug_id) FROM bugs_activity
  LEFT JOIN attachments ON attachments.attach_id = bugs_activity.attach_id
 INNER JOIN fielddefs ON bugs_activity.fieldid = fielddefs.id
 INNER JOIN profiles ON profiles.userid = bugs_activity.who
     WHERE bugs_activity.who = 'reed@reedloden.com'
       AND bugs_activity.bug_when >= '2008-03-01 00:00:00' AND bugs_activity.bug_when <= '2008-03-27 23:59:59'
       AND COALESCE(attachments.isprivate, 0) = 0

SELECT count(bugs_activity.bug_id) FROM bugs_activity
  LEFT JOIN attachments ON attachments.attach_id = bugs_activity.attach_id
 INNER JOIN fielddefs ON bugs_activity.fieldid = fielddefs.id
 INNER JOIN profiles ON profiles.userid = bugs_activity.who
     WHERE bugs_activity.who = 'reed@reedloden.com'
       AND bugs_activity.bug_when >= '2008-03-01 00:00:00' AND bugs_activity.bug_when <= '2008-03-27 23:59:59'

SELECT count(bugs_activity.bug_id) FROM bugs_activity
 INNER JOIN fielddefs ON bugs_activity.fieldid = fielddefs.id
 INNER JOIN profiles ON profiles.userid = bugs_activity.who
     WHERE bugs_activity.who = 'reed@reedloden.com'
       AND bugs_activity.bug_when >= '2008-03-01 00:00:00' AND bugs_activity.bug_when <= '2008-03-27 23:59:59'

SELECT count(bugs_activity.bug_id) FROM bugs_activity
 INNER JOIN profiles ON profiles.userid = bugs_activity.who
     WHERE bugs_activity.who = 'reed@reedloden.com'
       AND bugs_activity.bug_when >= '2008-03-01 00:00:00' AND bugs_activity.bug_when <= '2008-03-27 23:59:59'
Err, sorry. Also:

SELECT count(bugs_activity.bug_id) FROM bugs_activity
  LEFT JOIN attachments ON attachments.attach_id = bugs_activity.attach_id
  LEFT JOIN fielddefs ON bugs_activity.fieldid = fielddefs.id
 INNER JOIN profiles ON profiles.userid = bugs_activity.who
     WHERE bugs_activity.who = 'reed@reedloden.com'
       AND bugs_activity.bug_when >= '2008-03-01 00:00:00' AND
bugs_activity.bug_when <= '2008-03-27 23:59:59'
       AND COALESCE(attachments.isprivate, 0) = 0

which is the actual original query
The big this is the left join for fielddefs - this can be an inner join, and dave has confirmed that there aren't any non matching entries, which is a good sign that there aren't any historical bits. Anyone have an idea why its a left join? Custom fields only delete from fielddefs if its never been used, so thats not it. If this is changed, corresponding FK should be added.
Blocks: 425607
OS: Linux → All
Hardware: PC → All
Yeah, bbaetz is right about the INNER JOIN. Also, possibly adding a multi-column index on who,bug_when would help. (That wouldn't be needed upstream.)
The multicolumn index may help for frequent contributers, I guess. Lets see what the explains show.

Bug 425647 for adding FKs
and one more:

SELECT count(bugs_activity.bug_id) FROM bugs_activity
 INNER JOIN fielddefs ON bugs_activity.fieldid = fielddefs.id
 INNER JOIN profiles ON profiles.userid = bugs_activity.who
  LEFT JOIN attachments ON attachments.attach_id = bugs_activity.attach_id
     WHERE bugs_activity.who = 'reed@reedloden.com'
       AND bugs_activity.bug_when >= '2008-03-01 00:00:00' AND bugs_activity.bug_when <= '2008-03-27 23:59:59'
       AND COALESCE(attachments.isprivate, 0) = 0
FWIW, the left join and colaesce dates back to terry trying to manually reconstruct data after a botched schema update just over 8 years ago. See bug 425647 comment 1.
Well, the attachments left join makes sense--bugs_activity.attach_id is frequently NULL.
Yeah, but I'm trying to work out where the slow part is - it may be that it just has to be slow.
Attached file SQL + explain output
Here's your output from running the requested queries on mrdb06 (the production slave DB).  Each query was run twice, then run with EXPLAIN in front.
Bah, its getting lost in cache effects, I think. Hmm.

Dave, once more, without the bugs_activity.bug_when constraints?
Attached file SQL + explain output 2
again as requested
Sigh. Its cache effects again  8 seconds for the first, nothing for the rest

But even 8 seconds is < 60

Oh. Looking deeper, after the query it calls can_see_bug on each bug. Thats where the time is going, I suspect...

So this is a bmo specific issue. The Search.pm code should be reused, and if you really want to know how many hidden changes there are put the constraint into the SELECT bit rather than the WHERE clause, and just sum up as you go (possibly even in the template)
The hidden changes isn't all that important, so we could dump that.

We could also have a can_see_bugs subroutine instead, which might be simpler than trying to re-use the Search.pm API (which currently requires a CGI object).
Not necessarily reuse the whole code, but at least split that bit off somehow to avoid duplication of the security stuff.

It shouldn't require a CGI object, just something that you can call ->params on - it was designed that way for email-based queries and the like, as well as the xmlrpc stuff. But yeah, I'm not suggesting that for this. Although being able to search for all changes made by a user on a bug in certain products would be cute ;)
Rearranging this component to not have me as the default assignee, so that it doesn't appear like I'm intending to work on bugs that other people could be taking care of if they didn't think I was already doing them.  If this bug is a software issue on b.m.o and you'd like to fix it, the modified source is now available for the patching (see bug 373688).  Reassigning to the new default owner.
Assignee: justdave → nobody
QA Contact: reed → other-bmo-issues
Component: Bugzilla: Other b.m.o Issues → General
Product: mozilla.org → bugzilla.mozilla.org
Depends on: 425647
this customisation no longer exists.
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: