MySQL doesn't use index in join query
- by Kocsonya Laci
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!