|
Posted by Erland Sommarskog on 02/08/07 08:51
serge (sergea@nospam.ehmail.com) writes:
> declare @ContactId as integer
> set @ContactId = 5
> select *
> from Person.Contact
> where ContactId = @ContactId
> OR @ContactId = -1
>
> If you run this in SQL 2005 on the AdventureWorks database,
> why the logical reads is 561
> Table 'Contact'. Scan count 1, logical reads 56
>
> and not 2 when you run without the second OR condition:
Because the optimizer computes the plan, it does not know what the value of
@ContactId will be when the statement is executed.
I have a whole article on my web site on this topic,
http://www.sommarskog.se/dyn-search.html.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Navigation:
[Reply to this message]
|