# I have a simple table
create table t1 (c1 int, c2 int);
# I want to do the following sorting
select * from t1 order by c2 desc, c1 desc;
select * from t1 order by c2 asc, c1 desc;
# add indexs
CREATE INDEX index_1 ON t1 (c1 DESC, c2 DESC);
CREATE INDEX index_2 ON t1 (c1 ASC, c2 DESC);
# then explain
explain select * from t1 order by c2 desc, c1 desc;
# the result is
mysql> explain select * from t1 order by c2 desc, c1 asc;
+----+-------------+-------+-------+---------------+---------------+---------+------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------------+---------+------+------+-----------------------------+
| 1 | SIMPLE | t1 | index | NULL | index_2 | 10 | NULL | 6 | Using index; Using filesort |
+----+-------------+-------+-------+---------------+---------------+---------+------+------+-----------------------------+
1 row in set (0.00 sec)
My questions are
- Are the indexs optimized the performance?
- Why Using index; Using filesort show at the same time?