views:

160

answers:

3

Hello,

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?

+2  A: 

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...

ChssPly76
+1  A: 

You'd have to analyze the query. In general, it depends on the relative percentage of NULLs to values. If a majority of the entries in that integer column is NULL, that it will likely skip it.

On the other hand, if only 10% (for example) are NULL, it will (or should) use the index.

Frank V
A: 

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."

Sabeen Malik