You are here: Re: Views, UDFs « MsSQL Server « IT news, forums, messages
Re: Views, UDFs

Posted by Erland Sommarskog on 08/15/06 21:23

gherrell (greg.herrell@gmail.com) writes:
> I know there is a lot of information already out there on this topic,
> but given the following scenario...
>
> --------------------------------------------------------------------------
------------------------------------------------------------
> Create a view like so ( pardon the pseudo-code )...
>
> CREATE View vwContactAddresses
> Select * FROM Contact INNER JOIN Address ON Contact.ContactID =
> Address.ContactID
>
> And then do a sargable select from the view using a stored procedure
>
> CREATE STORED PROCEDURE spSelect_ContactAddresses
> @ContactID int
> AS
> Select * FROM vwContactAddresses WHERE ContactID = @ContactID
> --------------------------------------------------------------------------
------------------------------------------------------------
>
> In my understanding, "vwContactAddresses" would be substituted with the
> actual SQL join statement when the view is accessed.
>
> So for the stored procedure in question an execution plan for
> "Select * FROM Contact INNER JOIN Address ON Contact.ContactID =
> Address.ContactID WHERE ContactID = @ContactID" would be cached.
> Correct?

Not really. What is in the cache is a plan for the stored procedure
spSelect_ContactAdresses.

While the operators in the plan are likely to be same as in the plans
for "Select * FROM vwContactAddresses WHERE ContactID = @ContactID" and
"Select * FROM Contact INNER JOIN Address ON Contact.ContactID =
Address.ContactID WHERE ContactID = @ContactID" they are three different
cache entries. In fact, the plan is case- and space-sensitive, so all these
three are different cache entries:

SELECT col1 FROM tbl
Select col1 FROM tbl
SELECT col1 FROM tbl




--
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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация