Re: inner join on range criteria: unable to use index?
Here's another example that doesn't involve a join:
CREATE TABLE `probeinfo` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) default NULL,
`chr` varchar(30) default NULL,
`start` bigint(20) default NULL,
`stop` bigint(20) default NULL,
PRIMARY KEY (`id`),
KEY `start` (`start`,`stop`,`chr`)
) ENGINE=InnoDB
explain select * from probeinfo where chr='chr1' and start >= 935365 AND stop <=991355;
+----+-------------+-----------+------+---------------+------+---------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+------+---------------+------+---------+------+----------+-------------+
| 1 | SIMPLE | probeinfo | ALL | start | NULL | NULL | NULL | 26461244 | Using where |
+----+-------------+-----------+------+---------------+------+---------+------+----------+-------------+
The index appears in possible_keys but isn't actually used.
Using force index changes things slightly:
mysql> explain select * from probeinfo force index (start) where chr='chr1' and start >= 935365 AND stop <=991355;
+----+-------------+-----------+-------+---------------+-------+---------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+-------+---------------+-------+---------+------+----------+-------------+
| 1 | SIMPLE | probeinfo | range | start | start | 18 | NULL | 13230622 | Using where |
+----+-------------+-----------+-------+---------------+-------+---------+------+----------+-------------+
Notice that 'rows' is still 13 million.
A bit more data: the table has 26 million rows, and the query would return 145 rows.
Subject
Views
Written By
Posted
10417
August 11, 2008 04:34PM
3696
August 11, 2008 05:56PM
Re: inner join on range criteria: unable to use index?
3754
August 11, 2008 06:04PM
3570
August 12, 2008 01:38AM
3242
August 12, 2008 09:30AM
3186
August 12, 2008 07:11PM
3709
August 12, 2008 12:52PM
3063
September 26, 2008 11:38PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.