More than 100 ms different between sp_executesql and direct query

  • Hello All,

    I'm tracking down a performance issue with merge replication. I found a query that is executed large number of times and was taking anywhere between 50ms to 130ms. This is the query -
    exec sys.sp_executesql N'update dbo.MSmerge_sessions set subid = @subid where session_id = @session_id',
              N'@subid uniqueidentifier, @session_id int', @subid=@subid, @session_id=@session_id

    The interesting part is that the query inside "update dbo.MSmerge_sessions set subid = @subid where session_id = @session_id" takes only 1ms-2ms. I'm not understanding why is this

    SQL profiler output is below. This is not from 2 separate executions. It is from the execution of higher level sp_executesql executing lower level direct statement. HIghlighted numbers are duration -

     SP:StmtCompleted    update dbo.MSmerge_sessions set subid = @subid where session_id = @session_id    Replication Merge Agent        0    6    0    1    3360    60    2017-05-31 14:25:10.370    2017-05-31 14:25:10.370        
    SP:StmtCompleted    exec sys.sp_executesql N'update dbo.MSmerge_sessions set subid = @subid where session_id = @session_id',
              N'@subid uniqueidentifier, @session_id int', @subid=@subid, @session_id=@session_id
          Replication Merge Agent    0    6    0    115    3360    60    2017-05-31 14:25:10.370    2017-05-31 14:25:10.487    
        

    Any ideas on why sp_executesql adding so much time?

  • Please Ignore this. I figured it out.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply