SqlServer AdoJobStore SqlParameter without text size generates pressure on server
See original GitHub issueThe AdoJobStore implementation was recently fixed for the sched_name parameter in 3.1.0 but is still having pressure on Sql Server plan cache due to the missing SqlParameter size property for text parameters.
This generates a lot of distinct sql plans. Here some plans generated, this is the 3.0.0 version without the fix on scheduler name parameter but the issue still remains in latest:
(@triggerRepeatCount int,@triggerRepeatInterval bigint,@triggerTimesTriggered int,@triggerName nvarchar(12),@triggerGroup nvarchar(17))UPDATE QRTZ_SIMPLE_TRIGGERS SET REPEAT_COUNT = @triggerRepeatCount, REPEAT_INTERVAL = @triggerRepeatInterval, TIMES_TRIGGERED = @triggerTimesTriggered WHERE SCHED_NAME = 'scheduler' AND TRIGGER_NAME = @triggerName AND TRIGGER_GROUP = @triggerGroup
(@triggerRepeatCount int,@triggerRepeatInterval bigint,@triggerTimesTriggered int,@triggerName nvarchar(10),@triggerGroup nvarchar(10))UPDATE QRTZ_SIMPLE_TRIGGERS SET REPEAT_COUNT = @triggerRepeatCount, REPEAT_INTERVAL = @triggerRepeatInterval, TIMES_TRIGGERED = @triggerTimesTriggered WHERE SCHED_NAME = 'scheduler' AND TRIGGER_NAME = @triggerName AND TRIGGER_GROUP = @triggerGroup
As you can see without the parameter size it take the size from the value itself generating similar plans. To watch the plan cache generated on a SqlServer:
SELECT DISTINCT dm_exec_sql_text.text, creation_time FROM sys.dm_exec_cached_plans CROSS APPLY sys.dm_exec_query_plan(plan_handle) INNER JOIN sys.dm_exec_query_stats ON dm_exec_query_stats.plan_handle = dm_exec_cached_plans.plan_handle CROSS APPLY sys.dm_exec_sql_text(dm_exec_query_stats.plan_handle) WHERE text LIKE '%qrtz%' ORDER BY dm_exec_sql_text.text DESC;
This port to a plan flooding that has a critical impact on the entire server.
To avoid that we can gather at startup the column size from the schema and set that value during parametrization, I think in SqlServerDelegate.AddCommandParameter for example.
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (15 by maintainers)
Top GitHub Comments
I tested NHibernate 5.1.2 version, it set a fixed default value of 4000 for nvarchar when querying a mapped column with [StringLength(50)] and the same size on database column
EXEC sp_executesql N'select this_.Id as id1_7_0_, ... from dbo.test this_ where this_.Description=@p0',N'@p0 nvarchar(4000)',@p0 = N'test';
same thing during insert and update. I can’t test Entity Framework but I clearly rember in version 6 something similar. I tested Dapper 2.0.35 and it set a fixed default value of 4000 when not specified through parameters on a column with database size of 50 chars.exec sp_executesql N'SELECT COUNT(*) FROM [dbo].[test] WHERE [Description] = @Name',N'@Name nvarchar(4000)',@Name=N'test'
I think we can consider a good solution set it as 4000 size as default value.a useful link reference from Brent Ozar on the SqlParameter issue on Plan Cache pollution.
MSDN documentation of SqlParameter.Size usage