I've got a loop which updates thousands of objects with information retrieved from external sources. Sql Profiler shows that sp_executesql is executed with the same parameterized query, but the parameter definition list varies. This causes Sql Server to create a new execution plan, and I quickly get thousands of cached execution plans.
Information from SQL Profiler:
exec sp_executesql N'UPDATE Works SET LocalId = @p0, WorkId = @p1, Created = @p2, PublishedYear = @p3, Title = @p4, UniformTitle = @p5, Serie = @p6, Language = @p7, FullTextField = @p8, MarcXml = @p9, Catalog = @p10, MediaType = @p11 WHERE Id = @p12',N'@p0 int,@p1 uniqueidentifier,@p2 datetime,@p3 int,@p4 nvarchar(11),@p5 nvarchar(4000),@p6 nvarchar(13),@p7 nvarchar(3),@p8 nvarchar(2),@p9 nvarchar(3082),@p10 uniqueidentifier,@p11 uniqueidentifier,@p12 uniqueidentifier', ...
exec sp_executesql N'UPDATE Works SET LocalId = @p0, WorkId = @p1, Created = @p2, PublishedYear = @p3, Title = @p4, UniformTitle = @p5, Serie = @p6, Language = @p7, FullTextField = @p8, MarcXml = @p9, Catalog = @p10, MediaType = @p11 WHERE Id = @p12',N'@p0 int,@p1 uniqueidentifier,@p2 datetime,@p3 int,@p4 nvarchar(31),@p5 nvarchar(4000),@p6 nvarchar(32),@p7 nvarchar(3),@p8 nvarchar(2),@p9 nvarchar(1740),@p10 uniqueidentifier,@p11 uniqueidentifier,@p12 uniqueidentifier', ...
These parameters, and some of the others, varies between every call, causing thousands of execution plans to be created and cached.
I've done some research and looked at the GenerateCommand/InitializeParameter methods in the Driver class, and the possibility to override these, but I do not know how I would read the current mappings and update the parameter information. What's the best way to solve this?
|