I'm running a few mysql queries, and noticed some really slow behavior.
I ran the explain, and on the first query, only one index is being used when there should be two, and in the second query no index is being used.
Here are the explain outputs.
the indexes I expected would be used are
location_idx - which indexes address city state
getshows_idx which indexes lat, long date
I understand why the second search would use the getshows_idx, but thought both should use location_idx.
Is that not correct?
I ran the explain, and on the first query, only one index is being used when there should be two, and in the second query no index is being used.
Here are the explain outputs.
Code:
mysql> EXPLAIN SELECT `lat` , `long` FROM updateshows WHERE city = 'Philladelphia' AND state = 'Pennsylvania' LIMIT 0 , 1; +----+-------------+-------------+------+---------------+------+---------+------+---------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------------+------+---------------+------+---------+------+---------+-------------+ | 1 | SIMPLE | updateshows | ALL | NULL | NULL | NULL | NULL | 1581987 | Using where | +----+-------------+-------------+------+---------------+------+---------+------+---------+-------------+ 1 row in set (0.00 sec) mysql> EXPLAIN SELECT `lat` , `long` FROM updateshows WHERE city = 'Philladelphia' AND state = 'Pennsylvania' AND lat !=0 LIMIT 0 , 1; +----+-------------+-------------+-------+---------------+--------------+---------+------+---------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------------+-------+---------------+--------------+---------+------+---------+-------------+ | 1 | SIMPLE | updateshows | range | getshows_idx | getshows_idx | 4 | NULL | 1125490 | Using where | +----+-------------+-------------+-------+---------------+--------------+---------+------+---------+-------------+ 1 row in set (1.37 sec)
location_idx - which indexes address city state
getshows_idx which indexes lat, long date
I understand why the second search would use the getshows_idx, but thought both should use location_idx.
Is that not correct?
Comment