Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQLExec to return empty record
Message
From
19/03/2003 12:53:50
 
 
To
19/03/2003 09:54:38
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00767402
Message ID:
00767663
Views:
13
SQL Server's optimizer is smart enough to recognize that the predicate always evaluates to FALSE. So it doesn't have to do anything except form the metadata that makes up the result set.

Here's the show plan that is created:
StmtText                           
---------------------------------- 
select * from contact where 1=0

StmtText            
------------------- 
  |--Constant Scan
And to give you an idea, if we make a simple change so that we're using a variable instead of a constant, this is the showplan that gets generated:
StmtText                                 
---------------------------------------- 
declare @x int
set @x = 1

select * from contact where @x = 0


StmtText                                                                                                                   
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  |--Filter(WHERE:(STARTUP EXPR([@x]=0)))
       |--Compute Scalar(DEFINE:([contact].[reversePhone_pager]=reverse([contact].[phone_pager]), [contact].[reversePhone_fax]=reverse([contact].[phone_fax]), [contact].[reversePhone_mobile]=reverse([contact].[phone_mobile]), [contact].[reversePhone_work]=reverse([contact].[phone_work]), [contact].[reversePhone_home]=reverse([contact].[phone_home])))
            |--Clustered Index Scan(OBJECT:([gs13].[dbo].[contact].[cidx_contact_groupid_contactid]))
Which is really interesting because it shows that SQL Server can optimize the predicate to either a TRUE nor FALSE until execution. So it has decided to scan the clustered index (basically doing a table scan) and evaluating the expression as part of the filter.

-Mike

>>
>>... WHERE 1=2
>>
>
>Interesting, that works. But, what exactly does that tell SQL Server in order to returns an empty cursor?
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform