Following query will tell you whether query uses index or not:
EXPLAIN EXTENDED SELECT col1, col2, col3, COUNT(1)
FROM table_name
WHERE col1 = val
GROUP BY col1
ORDER BY col2;
SHOW WARNINGS;
You can add covering index for best performance.
For covering index you add columns used in where clauses first then columns used in group by the columns used in order by and then columns used in select.
e.g. for above query you can add covering index KEY(col1, col2, col3)
*Note Adding more indexes will slow down your insert queries.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…