SQL Server 2012 : Plan Guides.

  • Hello Experts

    WAs trying to explore about Plan Guides. Created few plan guides (taken from MSDN), but unable to determine, how that is going to help me.

    IF OBJECT_ID(N'Sales.GetSalesOrderByCountry', N'P') IS NOT NULL

    DROP PROCEDURE Sales.GetSalesOrderByCountry;

    GO

    CREATE PROCEDURE Sales.GetSalesOrderByCountry

    (@Country_region nvarchar(60))

    AS

    BEGIN

    SELECT *

    FROM Sales.SalesOrderHeader AS h

    INNER JOIN Sales.Customer AS c ON h.CustomerID = c.CustomerID

    INNER JOIN Sales.SalesTerritory AS t

    ON c.TerritoryID = t.TerritoryID

    WHERE t.CountryRegionCode = @Country_region;

    END

    EXEC sp_create_plan_guide

    @name = N'Guide1',

    @stmt = N'SELECT *

    FROM Sales.SalesOrderHeader AS h

    INNER JOIN Sales.Customer AS c

    ON h.CustomerID = c.CustomerID

    INNER JOIN Sales.SalesTerritory AS t

    ON c.TerritoryID = t.TerritoryID

    WHERE t.CountryRegionCode = @Country_region',

    @type = N'OBJECT',

    @module_or_batch = N'Sales.GetSalesOrderByCountry',

    @params = NULL,

    @hints = N'OPTION (OPTIMIZE FOR (@Country_region = N''US''))';

    Can anyone please suggest after creating the above plan-guide, what next to be done to utilize this feature the most?

    Thanks.

  • Instead of writing two sepereate blcks, can I not modify the SP with the below string?

    IF OBJECT_ID(N'Sales.GetSalesOrderByCountry', N'P') IS NOT NULL

    DROP PROCEDURE Sales.GetSalesOrderByCountry;

    GO

    CREATE PROCEDURE Sales.GetSalesOrderByCountry

    (@Country_region nvarchar(60))

    AS

    BEGIN

    SELECT *

    FROM Sales.SalesOrderHeader AS h

    INNER JOIN Sales.Customer AS c ON h.CustomerID = c.CustomerID

    INNER JOIN Sales.SalesTerritory AS t

    ON c.TerritoryID = t.TerritoryID

    WHERE t.CountryRegionCode = @Country_region

    OPTION (OPTIMIZE FOR (@Country_region = N'US'));

    END

    Thanks.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply