
create table `test1` (
`id` int not null auto_increment,
`videoid` int not null default 0,
`memid` int not null default 0,
primary key (`id`),
key `idx_videoid` (`videoid`)
插入1000条测试数据,
最开始
mysql> explain select * from test1 order by memid\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: test1
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 1000
filtered: 100.00
Extra: Using filesort
后来在memid 字段上创建索引之后,
mysql> show index from test1;
+-------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment | Visible | Expression |
+-------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+---------+------------+
| test1 | 0 | PRIMARY | 1 | id | A | 1000 | NULL | NULL | | BTREE | | | YES | NULL |
| test1 | 1 | idx_videoid | 1 | videoid | A | 1000 | NULL | NULL | | BTREE | | | YES | NULL |
| test1 | 1 | idx_memid | 1 | memid | A | 1000 | NULL | NULL | | BTREE | | | YES | NULL |
+-------+------------+-------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+----
mysql> analyze table test1;
+------------+---------+----------+----------+
| Table | Op | Msg_type | Msg_text |
+------------+---------+----------+----------+
| test.test1 | analyze | status | OK |
+------------+---------+----------+----------+
1 row in set (0.04 sec)
mysql> explain select * from test1 order by memid\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: test1
partitions: NULL
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 1000
filtered: 100.00
Extra: Using filesort
收集统计信息之后,怎么还是Using filesort ,并且索引也没有使用上?