MySQL Forums
Forum List  »  Newbie

Optimizing GROUP BY
Posted by: rihad rihad
Date: December 23, 2008 02:11AM

I want to optimize a slow query for speed, after reading this: http://dev.mysql.com/doc/refman/5.1/en/group-by-optimization.html

EXPLAIN SELECT SUM(uid) FROM logs WHERE uid='206' and start>='2008-12-16' GROUP BY uid ORDER BY NULL;
+----+-------------+----------+-------+---------------+------+---------+------+------+-------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+-------+---------------+------+---------+------+------+-------------------------------------------+
| 1 | SIMPLE | logs | range | uid | uid | 12 | NULL | 1 | Using where; Using index; Using temporary |
+----+-------------+----------+-------+---------------+------+---------+------+------+-------------------------------------------+

uid is NOT a PK. There is a single multi-key:
KEY `uid` (`uid`,`start`)
It's a BTREE index (InnoDB).

ORDER BY NULL was added in an attempt to avoid using temporary tables, but it's still there. Can someone please help? This is an example query please pay no attention if it doesn't make sense.

P.S.: what does "Using where" mean?



Edited 1 time(s). Last edit at 12/23/2008 02:13AM by rihad rihad.

Options: ReplyQuote


Subject
Written By
Posted
Optimizing GROUP BY
December 23, 2008 02:11AM
December 23, 2008 11:43AM
December 23, 2008 10:45PM
December 24, 2008 02:54AM
December 24, 2008 03:05AM
December 24, 2008 05:20PM
December 24, 2008 04:13AM
December 24, 2008 05:27PM
December 24, 2008 12:25PM


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.