Quantcast
Channel: Fórum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15680

Plan Guide Template Forced Parameterization Not Working (SIMPLE QUERY)

$
0
0

Hi,

I need assistance with getting a forced parameterization query plan to work.

The database has 'optimize for ad hoc workloads' disabled. The database is also set to a compatibility mode of 100.

You will notice that there is a space between the table owner qualifer. I've tried it both ways. Spaces should be ignored anyways.

The query does return data. You will notice that the plan cache doesn't show the prepared version which I suspect it should.I ran the queries a couple of times which is why the usecount and execution count are 2.

Thank you.

DECLARE @stmt nvarchar(max);
DECLARE @params nvarchar(max);

EXEC sp_get_query_template 
N'SELECT HasPatientBeenMadeDNRAtTOCId FROM dbo.Compliance WHERE HasPatientBeenMadeDNRAtTOCId = 2',
@stmt OUTPUT, 
@params OUTPUT;
		
EXEC sp_create_plan_guide 
 N'TemplateGuide1', 
 @stmt, 
 N'TEMPLATE', 
 NULL, 
 @params, 
 N'OPTION(PARAMETERIZATION FORCED)';

-- Output of @stmt variable
select HasPatientBeenMadeDNRAtTOCId from dbo . Compliance where HasPatientBeenMadeDNRAtTOCId = @0

-- Output of @params variable
@0 int

-- Queries issued to use the prepared plan from template (matches @stmt)
select HasPatientBeenMadeDNRAtTOCId from dbo . Compliance where HasPatientBeenMadeDNRAtTOCId = 1

select HasPatientBeenMadeDNRAtTOCId from dbo . Compliance where HasPatientBeenMadeDNRAtTOCId = 2

-- Plan cache output
Object Type	Cache Object Type	Ref Counts	Use Counts	Execution Counts	Query
Adhoc		Compiled Plan		2           	2           	2			select HasPatientBeenMadeDNRAtTOCId from dbo . Compliance where HasPatientBeenMadeDNRAtTOCId = 2
Adhoc		Compiled Plan		2           	2           	2			select HasPatientBeenMadeDNRAtTOCId from dbo . Compliance where HasPatientBeenMadeDNRAtTOCId = 1


Viewing all articles
Browse latest Browse all 15680

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>