יום חמישי, 25 בספטמבר 2008

Cumulative update package 1 for SQL Server 2008

The first cumulative update for SQL Server 2008 has been shipped. It can be downloaded here:
Cumulative Update 1 contains hotfixes for the Microsoft SQL Server 2008 issues that have been fixed since the release of SQL Server 2008.

יום שלישי, 16 בספטמבר 2008

RECOMPILE

כאשר אנו מריצים משפט T-SQL מול שרת בסיס הנתונים, ה- MSSQL ראשית מחפש ב- procedure cache האם הרצתי כבר את המשפט בעבר, והאם יש לי execution plan כבר מוכן.
במידה ואין לי – ה- MSSQL מייצר עבורי את execution plan ומריץ את השאילתא,
במידה ויש לי – ה- MSSQL משתמש ב- execution plan הקיים ומריץ את השאילתא.

ישנם מקרים בהם אני לא מעוניין שה- SQL server ישתמש ב- execution plan הקיים , אלה אני רוצה לאלץ אותו לבנות עבורי execution plan חדש.

כיצד ניתן לבצע זאת?

1. ניתן להוסיף ישירות לקוד את ה- hint - WITH RECOMPILE, לדוגמא:
CREATE PROCEDURE dbo.uspProductByVendor @Name varchar(30) = '%'
WITH RECOMPILE
AS
SELECT v.Name AS 'Vendor name', p.Name AS 'Product name'
FROM Purchasing.Vendor AS v
JOIN Purchasing.ProductVendor AS pv
ON v.VendorID = pv.VendorID
JOIN Production.Product AS p
ON pv.ProductID = p.ProductID
WHERE v.Name LIKE @Name;
GO


2. ניתן להוסיף לפקודת הרצת הפרוצדורה את ה- hint - WITH RECOMPILE , לדוגמא:

exec search_orders_3 @orderid = 11000 WITH RECOMPILE



3. בפלטפורמת SQL server 2005 ניתן גם להוסיף לשאילתא את HINT :
OPTION (RECOMPILE)

בהצלחה !