请教这个语句如何优化,不甚感激

请教如何利用好索引加快查询速度

语句如下:
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`),
) 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)

作者: sissiyam   发布时间: 2011-05-05

本帖最后由 horizonhyg 于 2011-05-05 17:13 编辑

回复 sissiyam


    给他们创建一个联合索引试试
    参考sql优化

作者: horizonhyg   发布时间: 2011-05-05

回复 horizonhyg


    使用联合索引之后,rows exam的行数看起来减少很多,但是实际上执行花的时间更多

作者: sissiyam   发布时间: 2011-05-05