EXPLAIN SELECT * FROM content_link link STRAIGHT_JOIN content ON link.content_id = content.id WHERE link.content_id = 1 LIMIT 10; +----+-------------+---------+-------+---------------+------------+---------+-------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+-------+---------------+------------+---------+-------+------+-------+ | 1 | SIMPLE | link | ref | content_id | content_id | 4 | const | 1 | | | 1 | SIMPLE | content | const | PRIMARY | PRIMARY | 4 | const | 1 | | +----+-------------+---------+-------+---------------+------------+---------+-------+------+-------+
However, when I delete WHERE, the request stops using the key (even if I explicitly force it)
EXPLAIN SELECT * FROM content_link link FORCE KEY (content_id) STRAIGHT_JOIN content ON link.content_id = content.id LIMIT 10; +----+-------------+---------+--------+---------------+---------+---------+------------------------+---------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+---------+--------+---------------+---------+---------+------------------------+---------+-------------+ | 1 | SIMPLE | link | index | content_id | PRIMARY | 7 | NULL | 4555299 | Using index | | 1 | SIMPLE | content | eq_ref | PRIMARY | PRIMARY | 4 | ft_dir.link.content_id | 1 | | +----+-------------+---------+--------+---------------+---------+---------+------------------------+---------+-------------+
Are there any workarounds?
I understand that in the second example, I select the entire table, but why did mysql suddenly decide that it would ignore my FORCE anyway and not use the key? Without a key, the request takes 10 minutes. Ugh.
source share