FineTune TSQL SQL Server -
the below query takes lot of time, 80 minutes return 1400 results, recommendation how tune
exec sp_executesql n'set arithignore on; select top (@solutionid) b.[solutionid],max(b.title) title, min(a.[status]) [status], min(a.[audience]) audience, max(b.productname) productname, min(cast( datecreated datetime)) datecreated , min(cast( datelastmodified datetime)) datemodified, [pc_pres_text]=replace(replace(replace((select [pc_pres_text] [data()] [dbo.view] a.[solutionid]=b.[solutionid] xml path('''')), ''<'',''<''),''>'',''>'') ,''&'',''&''), ''http://support/supp=''+b.[solutionid] primusurl [view] b inner join [table] on b.solutionid=a.solutionid ((@audience null , [audience] null) or [audience] @audience) , [datecreated] > @datecreated , ((@status null , [status] null) or [status] = @status) group b.[solutionid] order b.[solutionid]',n'@audience nvarchar(10),@datecreated datetime,@status nvarchar(9),@solutionid bigint', @audience=n'test%',@datecreated='2000-01-01 00:00:00',@status=n'test',@solutionid=500000
if passing parameter @audience , @status no need test null condition not going performance. if not output xml still have performance problem? include hint (nolock) or possibly (holdlock). not sure can (holdlock) on view - might need break down tables (holdlock). why cast on datecreated , datelastmodified - text fields in sql? if text , cast datetime why not store them datetime?
Comments
Post a Comment