创建表:
CREATE TABLE `doh`.`test` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(45) NULL ,
`age` INT NOT NULL DEFAULT 0 ,
PRIMARY KEY (`id`) ,
INDEX `age_index` USING BTREE (`age` DESC) )
ENGINE = InnoDB;
explain select id,name,age from test order by age desc limit 10
得到的结果
mysql> explain select id,name,age from test order by age desc limit 10;
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | test | ALL | NULL | NULL | NULL | NULL | 1 | Using filesort |
+----+-------------+-------+------+---------------+------+---------+------+------+----------------+
1 row in set (0.00 sec)
还是使用filesort,并没有使用age_index这个索引,这是什么原因呢?
作者: funkworld
发布时间: 2011-08-02