I'm getting this warning:
No index used in query/prepared statement SELECT * FROM mTable WHERE my_column IS NULL
But the my_column
is already indexed.
MariaDB [mytest]> SHOW INDEX FROM mTable;
+--------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
+--------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
| mTable | 0 | PRIMARY | 1 | id | A | 11 | NULL | NULL | | BTREE | | |
| mTable | 1 | my_column | 1 | my_column | A | 11 | NULL | NULL | YES | BTREE | | |
+--------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
Reason maybe is my_column
actually contains NULL
values so there's literally no index that's why MySQL complains? But then I have to query columns that are NULL
.
Any ideas for a better approach on this?
SHOW
you provide.INDEX
,NULL
is a value. There as many 'rows' in an index as there are rows in the data, regardless of whether some (or all) of the values areNULL
.