MySQL index question

I am trying to speed up some DB operations and perhaps have gone overboard
with indexes. Does MySQL usually use only one index per query and simply
match keys on the results of the indexed first part? For example:

DELETE FROM tokens WHERE 6813946236211560448 <= fnv AND fnv < 6818449835838930944 AND updated_at<'2010-06-20 14:08:55' AND occurrences=0;

If I understand correctly from the output of:

EXPLAIN SELECT * FROM tokens WHERE 6813946236211560448 <= fnv AND fnv < 6818449835838930944 AND updated_at<'2010-06-20 14:08:55' AND occurrences=0;

only the index on fnv is used (there are indexes on updated_at and
occurrences).

Is this correct?

TIA,
  Jeffrey

I am trying to speed up some DB operations and perhaps have gone overboard
with indexes. Does MySQL usually use only one index per query and simply
match keys on the results of the indexed first part? For example:

one one index will be used per table

DELETE FROM tokens WHERE 6813946236211560448 <= fnv AND fnv < 6818449835838930944 AND updated_at<'2010-06-20 14:08:55' AND occurrences=0;

If I understand correctly from the output of:

EXPLAIN SELECT * FROM tokens WHERE 6813946236211560448 <= fnv AND fnv < 6818449835838930944 AND updated_at<'2010-06-20 14:08:55' AND occurrences=0;

only the index on fnv is used (there are indexes on updated_at and
occurrences).

Is this correct?

hard to say without said output :slight_smile:

Fred

Quoting Frederick Cheung <frederick.cheung@gmail.com>:

> EXPLAIN EXTENDED SELECT * FROM tokens WHERE 6813946236211560448 <= fnv AND fnv < 6818449835838930944 AND updated_at<'2010-06-20 14:08:55' AND occurrences=0;
+----+-------------+--------+-------+-------------------------------------- ------------------+---------------------------------+---------+------+----- -+-------------+
> id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------+-------+-------------------------------------- ------------------+---------------------------------+---------+------+----- -+-------------+
> 1 | SIMPLE | tokens | range | index_tokens_on_fnv_and_user_id,updated_at,occurrences | index_tokens_on_fnv_and_user_id | 8 | NULL | 6153 | Using where |
+----+-------------+--------+-------+-------------------------------------- ------------------+---------------------------------+---------+------+----- -+-------------+
1 row in set, 1 warning (0.00 sec)

Yup, that is just using the index on fnv.

Fred

Quoting Frederick Cheung <frederick.cheung@gmail.com>: