Stored Procedure failing on a specific user

后端 未结 5 554
悲哀的现实
悲哀的现实 2020-12-21 07:41

I have a Stored Procedure that is constantly failing with the error message \"Timeout expired,\" on a specific user.

All other users are able to invoke the sp just f

5条回答
  •  旧时难觅i
    2020-12-21 08:29

    Some thoughts...

    Reading the comments suggests that parameter sniffing is causing the issue.

    • For the other users, the cached plan is good enough for the parameter that they send
    • For this user, the cached plan is probably wrong

    This could happen if this user has far more rows than other users, or has rows in another table (so a different table/index seek/scan would be better)

    To test for parameter sniffing:

    • use RECOMPILE (temporarily) on the call or in the def. This could be slow for complex query
    • Rebuild the indexes (or just statistics) after the timeout and try again. This invalidates all cached plans

    To fix: Mask the parameter

    DECLARE @MaskedParam varchar(10)
    SELECT @MaskedParam = @SignaureParam
    
    SELECT...WHERE column = @MaskedParam
    

    Just google "Parameter sniffing" and "Parameter masking"

提交回复
热议问题