Jump to content

Why aren't my indexes being utilised?


gawi79

Recommended Posts

Hi,

 

I'm trying to run the following query on my database (mysql version: 5.0.26):

 

select chrom_X.* from chrom_X,repeats_alu where repeats_alu.chr = "X" and (chrom_X.start >= repeats_alu.start and chrom_X.stop <= repeats_alu.stop);

 

Performing an EXPLAIN of the above query produces:

 

mysql> explain select * from chrom_X,repeats_alu where repeats_alu.chr = "X" and (chrom_X.start >= repeats_alu.start and chrom_X.stop <= repeats_alu.stop);

+----+-------------+-------------+------+----------------------------------+-----------+---------+-------+---------+------------------------------------------------+

| id | select_type | table      | type | possible_keys                    | key      | key_len | ref  | rows    | Extra                                          |

+----+-------------+-------------+------+----------------------------------+-----------+---------+-------+---------+------------------------------------------------+

|  1 | SIMPLE      | repeats_alu | ref  | chr_index,start_index,stop_index | chr_index | 4      | const |  42036 | Using where                                    |

|  1 | SIMPLE      | chrom_X    | ALL  | start_index,stop_index                | NULL      | NULL    | NULL  | 1245807 | Range checked for each record (index map: 0xC) |

+----+-------------+-------------+------+----------------------------------+-----------+---------+-------+---------+------------------------------------------------+

2 rows in set (0.00 sec)

 

I want to increase the speed of the query. Both tables contain approx 1 million rows. Unfortunately MySQL isn't utilising the start_index and stop_index in my tables to perform this query? Any ideas as to why this may be the case?

 

The table structures are below:

 

| chrom_X | CREATE TABLE `chrom_X` (

  `id` int(10) NOT NULL auto_increment,

  `chr` char(2) NOT NULL,

  `start` int(10) NOT NULL,

  `stop` int(10) NOT NULL,

  PRIMARY KEY  (`id`),

  KEY `chr` (`chr`),

  KEY `stop_index` (`stop`),

  KEY `start_index` (`start`)

) ENGINE=MyISAM AUTO_INCREMENT=1245808 DEFAULT CHARSET=latin1 |

 

 

| repeats_alu | CREATE TABLE `repeats_alu` (

  `id` int(7) NOT NULL auto_increment,

  `chr` varchar(2) NOT NULL,

  `start` int(10) NOT NULL,

  `stop` int(10) NOT NULL,

  `strand` int(1) NOT NULL,

  PRIMARY KEY  (`id`),

  KEY `chr_index` (`chr`),

  KEY `start_index` (`start`),

  KEY `stop_index` (`stop`)

) ENGINE=MyISAM AUTO_INCREMENT=1086476 DEFAULT CHARSET=latin1 |

 

 

Many Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/152966-why-arent-my-indexes-being-utilised/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.