- 论坛徽章:
- 8
|
下面是我的测试过程,始终是使用s_u上的索引
方便的话,LZ将这个表倒出来上传到cu供大家测试下- mysql> show create table book\G
- *************************** 1. row ***************************
- Table: book
- Create Table: CREATE TABLE `book` (
- `book_id` int(11) NOT NULL AUTO_INCREMENT,
- `status` int(11) NOT NULL,
- `level` int(11) NOT NULL,
- `update_time` datetime DEFAULT NULL,
- `price` int(11) DEFAULT NULL,
- `actor` varchar(20) DEFAULT NULL,
- `pub` varchar(20) DEFAULT NULL,
- PRIMARY KEY (`book_id`),
- KEY `s_l_u` (`status`,`level`,`update_time`),
- KEY `s_u` (`status`,`update_time`)
- ) ENGINE=MyISAM AUTO_INCREMENT=72551 DEFAULT CHARSET=utf8
- 1 row in set (0.00 sec)
- mysql> select distinct status,count(*) from book group by status;
- +--------+----------+
- | status | count(*) |
- +--------+----------+
- | 1 | 9000 |
- | 2 | 28550 |
- | 3 | 10500 |
- | 4 | 12000 |
- | 5 | 1500 |
- | 6 | 11000 |
- +--------+----------+
- 6 rows in set (0.00 sec)
- mysql> select distinct level,count(*) from book group by level;
- +-------+----------+
- | level | count(*) |
- +-------+----------+
- | 0 | 72330 |
- | 1 | 220 |
- +-------+----------+
- 2 rows in set (0.10 sec)
- mysql> select distinct update_time,count(*) from book group by update_time;
- +---------------------+----------+
- | update_time | count(*) |
- +---------------------+----------+
- | 2012-04-11 15:14:25 | 11533 |
- | 2012-04-11 15:14:26 | 12853 |
- | 2012-04-11 15:14:27 | 12340 |
- | 2012-04-11 15:14:28 | 12019 |
- | 2012-04-11 15:14:29 | 12046 |
- | 2012-04-11 15:14:30 | 11588 |
- | 2012-04-11 15:14:31 | 171 |
- +---------------------+----------+
- 7 rows in set (0.11 sec)
- mysql> explain select update_time from book where status=2 order by update_time desc;
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | 1 | SIMPLE | book | ref | s_l_u,s_u | s_u | 4 | const | 20798 | Using where; Using index |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- 1 row in set (0.00 sec)
- mysql> explain select update_time from book where status=2 order by update_time desc limit 100,50;
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | 1 | SIMPLE | book | ref | s_l_u,s_u | s_u | 4 | const | 20798 | Using where; Using index |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- 1 row in set (0.00 sec)
- mysql> explain select update_time from book where status=2 order by update_time desc limit 28000,50;
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | 1 | SIMPLE | book | ref | s_l_u,s_u | s_u | 4 | const | 20798 | Using where; Using index |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- 1 row in set (0.00 sec)
- mysql> explain select update_time from book where status=2 order by update_time desc limit 20000,50;
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | 1 | SIMPLE | book | ref | s_l_u,s_u | s_u | 4 | const | 20798 | Using where; Using index |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- 1 row in set (0.00 sec)
- mysql> explain select update_time from book where status=2 order by update_time desc limit 10000,50;
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- | 1 | SIMPLE | book | ref | s_l_u,s_u | s_u | 4 | const | 20798 | Using where; Using index |
- +----+-------------+-------+------+---------------+------+---------+-------+-------+--------------------------+
- 1 row in set (0.00 sec)
复制代码 |
|