Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql Index Being Ignored
    primarykey
    data
    text
    <pre><code>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 | | +----+-------------+---------+-------+---------------+------------+---------+-------+------+-------+ </code></pre> <p>However, when I remove the WHERE, the query stops using the key (even when i explicitly force it to)</p> <pre><code>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 | | +----+-------------+---------+--------+---------------+---------+---------+------------------------+---------+-------------+ </code></pre> <p>Are there any work-arounds to this?</p> <p>I realize I'm selecting the entire table in the second example, but why does mysql suddenly decide that it's going to ignore my FORCE anyway and not use the key? Without the key the query takes like 10 minutes.. ugh.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload