question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SqlServer AdoJobStore SqlParameter without text size generates pressure on server

See original GitHub issue

The 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:closed
  • Created 3 years ago
  • Comments:15 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
lucamazzanticommented, Aug 22, 2020

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.

1reaction
lucamazzanticommented, Aug 22, 2020
  • a useful link reference from Brent Ozar on the SqlParameter issue on Plan Cache pollution.

  • MSDN documentation of SqlParameter.Size usage

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing SqlParameter from C# without datatype
I was wondering whether there are any performance implications when you don't use datatype and length while creation of parameters? How does SQL...
Read more >
quartznet/changelog.md at main
... SqlServer AdoJobStore SqlParameter without text size generates pressure on server (#939); DbProvider initialization logic should also read quartz.config ...
Read more >
SqlParameter.Size Property (System.Data.SqlClient)
Gets or sets the maximum size, in bytes, of the data within the column. ... The following example creates a SqlParameter and sets...
Read more >
Query Optimization Techniques in SQL Server: Parameter ...
In this blog post we will walk you through one of the SQL Query Optimization Techniques in SQL Server - Parameter Sniffing.
Read more >
Symptoms of Parameter Sniffing in SQL Server
In this article, we will focus on how we can detect the parameter sniffing issues with different techniques.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found