Query Performance with NULL

前端 未结 8 1994
失恋的感觉
失恋的感觉 2021-01-14 14:29

I would like to know about how NULL values affect query performance in SQL Server 2005.

I have a table similar to this (simplified):

ID | ImportantDa         


        
8条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-14 14:34

    Having a lot of NULLs in a column which has an index on it (or starting with it) is generally beneficial to this kind of query.

    NULL values are not entered into the index, which means that inserting / updating rows with NULL in there doesn't take the performance hit of having to update another secondary index. If, say, only 0.001% of your rows have a non-null value in that column, the IS NOT NULL query becomes pretty efficient as it just scans a relatively small index.

    Of course all of this is relative, if your table is tiny anyway, it makes no appreciable difference.

提交回复
热议问题