MySQL Forums
Forum List  »  Optimizer & Parser

Re: inner join on range criteria: unable to use index?
Posted by: Joseph Fisk
Date: August 11, 2008 06:04PM

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.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: inner join on range criteria: unable to use index?
3639
August 11, 2008 06:04PM


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.