|
本帖最后由 sissiyam 于 2011-4-28 20:25 编辑
请教如何利用好索引加快查询速度
语句如下:
mysql>select * from table1 where 3393547226 between ipfrom and ipto order by status desc, width desc limit 1;
表定义:
| table1 | CREATE TABLE ` table1` (
`id` int(11) NOT NULL auto_increment,
`ipfrom` int(10) unsigned NOT NULL default '0',
`ipto` int(10) unsigned NOT NULL default '0',
`width` int(10) unsigned NOT NULL default '0',
`status` enum('','aux','usr') NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ipfrom` (`ipfrom`),
KEY `ipto` (`ipto`),
KEY `auxSearch` (`ipfrom`,`ipto`)
) ENGINE=MyISAM AUTO_INCREMENT=134824497 DEFAULT CHARSET=latin1 |
mysql> explain select * from table1 where 3393547226 between ipfrom and ipto order by status desc, width desc limit 1;
+----+-------------+-------------------+-------+-----------------------+------+---------+------+------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------------+-------+-----------------------+------+---------+------+------+-----------------------------+
| 1 | SIMPLE | table1 | range | ipfrom,ipto,auxSearch | ipto | 4 | NULL | 9440 | Using where; Using filesort |
+----+-------------+-------------------+-------+-----------------------+------+---------+------+------+-----------------------------+
1 row in set (0.00 sec)
|
|