Forum Moderators: open

Message Too Old, No Replies

MySQL multiple index - stuck with large query

         

Sleeps

1:49 pm on Sep 13, 2007 (gmt 0)

10+ Year Member



I am stuck on a query I am trying to perform on a v large database (over 100 million tuples) and need to either optimize it somehow or create better indexes. The query is as follows (which gives the correct results on a small test database):

SELECT * FROM Results
WHERE Name = 'Chr1'
AND ( (Start >= 16300 AND Start <= 16400)
OR (End >= 16300 AND End <= 16400)
OR (Start < 16300 AND End > 16400) );

This query never completes so I am a bit stuck. I have created a multi index on the Name, Start and End columns using:

ALTER TABLE Results ADD INDEX (Name, Start, End);

If anyone has any ideas how to optimize the query or if I should be creating other indexes help would be much appreciated!

Also here is what an EXPLAIN gives for this query:
+----+-------------+-------------+------+---------------+-------+---------+-------+---------+-------------+
¦ id ¦ select_type ¦ table ¦ type ¦ possible_keys ¦ key ¦ key_len ¦ ref ¦ rows ¦ Extra ¦
+----+-------------+-------------+------+---------------+-------+---------+-------+---------+-------------+
¦ 1 ¦ SIMPLE ¦ Results ¦ ref ¦ Name ¦ Name ¦ 17 ¦ const ¦ 7757498 ¦ Using where ¦
+----+-------------+-------------+------+---------------+-------+---------+-------+---------+-------------+
1 row in set (0.02 sec)

Demaestro

9:14 pm on Sep 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What are the data types for the fields Start and End?

SeanW

1:24 am on Sep 21, 2007 (gmt 0)

10+ Year Member



Create separate indexes on start and end. With your composite index, mysql can not use the start and end fields to reduce the number of rows.

Sean