Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does mysql 5.0 index null values?

I realize that the exact question has been asked before on stack overflow with only a vaguely conclusive answer: link

So here it is again.

Table A: Has an integer column which is nullable, along with an index. Query:

SELECT * 
FROM table 
WHERE column IS NULL 
LIMIT 10;

Will an index be used, or will mysql do a full table scan until it has found 10 entries?

like image 626
BrainCore Avatar asked Oct 06 '09 23:10

BrainCore


2 Answers

i think this should be helpful:

http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html

A search using col_name IS NULL employs indexes if col_name is indexed.

like image 153
Sabeen Malik Avatar answered Oct 16 '22 06:10

Sabeen Malik


The only way to know that for sure in your specific case is to run "EXPLAIN SELECT" on your query.

It really depends on the number of NULLs in your table compared with total number of rows; whether table statistics have been updated, etc...

like image 27
ChssPly76 Avatar answered Oct 16 '22 05:10

ChssPly76