is it good to add index on column used in group by clause?

group-by, indexing, mysql, performance, query-optimization

Solution

Not only but also z,

ADD INDEX (z, x)

when there is composite index, column order is important. in you case, 'z' is compared to 100 firstly.

this like provides useful information about it. http://dev.mysql.com/doc/refman/5.5/en/mysql-indexes.html

and, MySQL has explained about GROUP BY Optimization http://dev.mysql.com/doc/refman/5.5/en/group-by-optimization.html

Problem

I have a query like- ``` SELECT x, SUM(y) FROM xyz WHERE z>=100 GROUP BY x ORDER BY SUM(y) DESC; ``` will it be faster if I am going to add index on x? Thank you.

Original source