MySQL Forums
Forum List  »  Performance

Re: Query Optimization Needed
Posted by: Peter Brawley
Date: February 12, 2015 01:24PM

Usually DISTINCT is implemented as GROUP BY and triggers a table scan, see http://dev.mysql.com/doc/refman/5.6/en/group-by-optimization.html, ie your query is likely being turned into ...

select deviceid
from userdeviceinfo
where created_on < '2015-02-10 18:30:00 and user_id is not null
group by deviceid;

... and you want to try to get Explain Extended to report ...

- `type` as range rather than index, and

- index use for group-by in the `Extra` column

- a reasonable number in the `filtered` column

A second or so for fetching 200k rows from a 500k-row table doesn't sound too bad. As I read the section on loose index scan in that manual page, putting the Group By column(s) first in the covering index might help. Worth a try.

How much RAM, what is innodb_buffer_pool_size?

Options: ReplyQuote


Subject
Views
Written By
Posted
1670
February 11, 2015 01:31AM
753
February 11, 2015 12:42PM
855
February 12, 2015 03:51AM
Re: Query Optimization Needed
786
February 12, 2015 01:24PM
754
February 13, 2015 06:53AM
687
February 13, 2015 07:36AM
706
February 14, 2015 01:04AM
781
February 15, 2015 11:07PM
798
February 16, 2015 12:15AM
659
March 13, 2015 11:15AM


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.