开发者

Optimizing this query

I'm trying to optimize the following query but I don't know what to do. I know little of query optimization but 开发者_C百科doesn't that key_len mean its searching through 386,386 rows? The cities table has 10,053 rows and states only 27.

SELECT c.city_name, s.state_name
FROM res_geo_cities AS c, res_geo_states AS s
WHERE c.id_state = s.id_state AND(
(
 (c.metaphone_primary IN ($one,$two) OR c.metaphone_secondary IN ($one,$two)) AND 
 (s.metaphone_primary IN ($three,$four) OR s.metaphone_secondary IN ($three,$four))
) OR (
 (c.metaphone_primary IN ($three,$four) OR c.metaphone_secondary IN ($three,$four)) AND 
 (s.metaphone_primary IN ($one,$two) OR s.metaphone_secondary IN ($one,$two))
))
LIMIT 50

This is the explain:

Optimizing this query

Could somebody be so kind as to point me in the right direction?


This means that you have two keys that each have a length of 386. Try rewriting this query with a join that has an 'ON' clause, instead of just selecting from multiple tables. Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜