Investigate Problem

Why doesn't MySQL use the index or key for my query?

Follow the prompts to identify the solution

proposes Do you have keys on the table? (You can check with: SHOW CREATE TABLE)

Yes Add

No Add

Yes

No

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Add additional info to your problem.

We'll personally review your case within 24 hours.

Help solve the problem by asking a question or proposing a solution.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Most common questions used to investigate

Do you have keys on the table? (You can check with: SHOW CREATE TABLE)

Are the columns in your keys used in in the WHERE section of the query?

Is the column in a function or equation? Like

Are both sides of the comparison of the same type?

Is your DB using a different index? You can check by putting EXPLAIN before your query.

Common conclusions

You need to add keys. The command is: ALTER TABLE the_table ADD KEY(column1, column2);

You need to ADD the index for MySQL to use it. The command is: ALTER TABLE the_table ADD KEY(column1, column2);

The col_name needs to be by itself for MySQL to use that columns key. For example, change POW(col,2) / 2 > 100 TO col > POW(200 * 2, 0.5)

The database may be converting the column to another type which stops the index from being used. CONVERT or CAST other side to the correct type.

Perhaps the database is using a different index. You can give the DB a hint like this:

Add more information to this case and I'll try to figure it out.

References
Related Problems