Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQLExec to return empty record
Message
De
19/03/2003 12:53:50
 
 
À
19/03/2003 09:54:38
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00767402
Message ID:
00767663
Vues:
12
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform