MySQL doesn't use index in join query
Posted
by
Kocsonya Laci
on Stack Overflow
See other posts from Stack Overflow
or by Kocsonya Laci
Published on 2012-07-09T09:12:16Z
Indexed on
2012/07/09
9:15 UTC
Read the original article
Hit count: 199
mysql
I have two tables: comments(id(primary key), author, ip(index)) and visitors(id(primary key), date_time, ip(index))
I want to join them like that:
SELECT visitors.date_time
FROM comments
LEFT JOIN visitors ON ( comments.ip = visitors.ip )
WHERE comments.author = 'author'
LIMIT 10
It works, but very slow.. In EXPLAIN it shows that it doesn't use the index on the visitors table:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE comments ref author author 78 const 9660 Using where
1 SIMPLE visitors ALL NULL NULL NULL NULL 8033
Any ideas? Thanks!
© Stack Overflow or respective owner