Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does MySQL not use an index on a int field that's being used as a boolean?

Tags:

indexing

mysql

select * from myTable where myInt

will not show any possible_keys when explaining the query even though there is an index on myInt field.

Edit:
The index in question is not unique.

like image 287
Senseful Avatar asked Mar 01 '23 03:03

Senseful


1 Answers

For MySQL to use the index, you have to explicitly compare the int field to a value (e.g. true, 1).

select * from myTable where myInt = true
like image 184
Senseful Avatar answered Mar 03 '23 19:03

Senseful