Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
EXISTS
Message
De
12/02/2001 08:50:33
 
 
À
09/02/2001 23:42:35
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Re: EXISTS
Divers
Thread ID:
00473986
Message ID:
00474913
Vues:
18
That's a really good question. To find out, I enabled the SHOWPLAN_TEXT option which spits out how SQL Server decided to solve the query.

The first query:
SELECT *
FROM titles
WHERE title_id NOT IN (
	SELECT title_id
	FROM sales )

  |--Nested Loops(Left Anti Semi Join, OUTER REFERENCES:([titles].[title_id]))
       |--Clustered Index Scan(OBJECT:([pubs].[dbo].[titles].[UPKCL_titleidind]))
       |--Index Seek(OBJECT:([pubs].[dbo].[sales].[titleidind]), SEEK:([sales].[title_id]=[titles].[title_id]) ORDERED FORWARD)
And the second:
SELECT *
FROM titles
WHERE NOT EXISTS (
	SELECT *
	FROM sales
	WHERE sales.title_id = titles.title_id)

  |--Nested Loops(Left Anti Semi Join, OUTER REFERENCES:([titles].[title_id]))
       |--Clustered Index Scan(OBJECT:([pubs].[dbo].[titles].[UPKCL_titleidind]))
       |--Index Seek(OBJECT:([pubs].[dbo].[sales].[titleidind]), SEEK:([sales].[title_id]=[titles].[title_id]) ORDERED FORWARD)
So what we're seeing is that the SQL Sever optimizer has decided to solve both queries the same way. Normally, you would be right. The subquery should be faster than the corrolated-subquery. But here we're seeing how smart the query opimizer is.

-Mike
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform