23 August 2006

Microsoft SQL Server and Ad-Hock queries optimization

Yesterday I was surprised to learn that Microsoft SQL Server 2005 makes behind the scene parameterization of ad-hock queries. For example, lets have the following query:
SELECT ID, Name FROM Article WHERE Price > 100

SQL Server 2005 will replace constant literal values (100 in this example) by variables and this way query plan will be reuses for all queries similar to
SELECT ID, Name FROM Article WHERE Price > @p1

Not all of the ad-hock queries can be parameterized. If you are interested read this article.

No comments: