Select top 1 with UPDLOCK and READPAST sets exclusive lock on the entire table

后端 未结 3 725
感动是毒
感动是毒 2021-01-05 04:44

I\'m using the UPDLOCK and READPAST sql hints in a stored procedure in order to implement a sort of a table queue (I say a sort because I select top 1500 instead of a top 1,

相关标签:
3条回答
  • 2021-01-05 05:24

    Here is how you use tables as queues: SQL Server Process Queue Race Condition

    Summary: you're missing ROWLOCK (which will use more resources in this case)

    0 讨论(0)
  • 2021-01-05 05:29

    That table probably has too many columns and should be split up. Maybe it's not in proper 3rd or 4th normal form.

    Another thing would be to make sure there is a covering index specifically for your query.

    0 讨论(0)
  • 2021-01-05 05:41

    I think your problem is indexing. Make sure you have the proper indexes on your table and make sure your queries always use that index. Having no, or the incorrect index can make SQL Server take a page lock or a table lock, which invalidates the whole model.

    0 讨论(0)
提交回复
热议问题