SQL Server, insert one row locks whole table

后端 未结 1 597
后悔当初
后悔当初 2021-01-04 12:04

We have an issue with some deadlock and I posted this question.

With some help and a lot of searching myself I believe I figured out what is going on. In order to so

相关标签:
1条回答
  • 2021-01-04 12:31

    I found the answer. A little blunder from a developer in our team (I always blame everybody else :-). I probably should have known the answer already because again, Martin Smith pointed out in the other question that I should check ALLOW_ROW_LOCKS and ALLOW_PAGE_LOCKS. But at that time we thought that partitionid related to an index id and I only checked that index.

    What I did was creating a new table with the same data. The effect was gone and I only had the correct IX lock on the new table. Then I created every index and tested between every creation until I suddenly had the effect again.

    I found this index on OurTable:

    CREATE NONCLUSTERED INDEX [IX_OurTable] ON [dbo].[OurTable] 
    (
        [Col1] ASC,
        [Col2] ASC,
        [Col3] ASC,
        [Col4] ASC,
        [Col5] ASC
    )
    INCLUDE ( [Col6],
    [Col7],
    [Col8],
    [Col9]) WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = OFF, ALLOW_PAGE_LOCKS  = OFF, FILLFACTOR = 90) ON [PRIMARY]
    GO
    

    With ALLOW_ROW_LOCKS = OFF and ALLOW_PAGE_LOCKS = OFF it's obvious we would have this effect on the insert and also the selects.

    Thank you for your comments and many thanks to Martin who really helped me to solve these deadlock problems.

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