I have a table, let's call it History
. The primary key (aka Clustered Index) is called HIST_ID
. The table has some 2300 rows in the development DB. Now consider the following two queries:
Query 1:
declare @x int
set @x = 14289
select * from History where hist_id=@x
Query 2:
declare @x int
set @x = 14289
select * from History where hist_id=@x or @x is null
The only difference is the or @x is null
at the end. However the first query does an index seek, the second - index scan. What gives?
Pre-emptive reply - no, option(recompile) doesn't help.
Added: I'd like some solid argumented facts, not guesses. I can guess a dozen possible reasons for this myself. But what is the real problem here?