MySQL Forums
Forum List  »  Optimizer & Parser

Re: Optimize sub query with large group by
Posted by: Rick James
Date: March 13, 2011 03:52PM

select  person_id, count(id)
    from  
      ( SELECT  id, person_id
            from  events
            group by  object_id) as subquery
    group by  person_id;
Subqueries are not well optimized. But, before suggesting what to do in this case, let's dissect the subquery; it does not make sense:
SELECT id, person_id
from events
group by object_id
Normally on does a GROUP BY on one of the items in the SELECT list, and the rest of the fields in the SELECT list are 'aggregates' such as MIN(), COUNT(). This GROUP BY comes no where near that.

Options: ReplyQuote


Subject
Views
Written By
Posted
3852
March 10, 2011 07:44PM
Re: Optimize sub query with large group by
2162
March 13, 2011 03:52PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.