There is a table that seems to have constant updates. There is also a stored procedure that runs periodically and iterates through tables and attempts to truncate a partition of data using the command below:
TRUNCATE TABLE [dbo].[Table] WITH (PARTITIONS (10))
The looping procedure always gets locked up on the same table, the table with constant updates fails even when data is not being updated in the partition targeted for deletion.
The calling process can't be updated. Is there a trick to bind the updates to a partition outside of modifying the query or some other way to force non changing partitions to not be blocked/locked?
Will a page lock cause truncate with partition to fail? Like could two partitions share a single page and attempting to delete with partition(2) fails because some process is updating data in partition 1 that 2 happens to be sharing a page with?
CREATE TABLE [dbo].[Table]
(
[TableID] INT NOT NULL
...
, [SourceID] NVARCHAR(4000) NOT NULL
, CONSTRAINT [PK_Table_TableID] PRIMARY KEY NONCLUSTERED([TableTableID] ASC , [SourceID] ASC) ON psSourceID(SourceID)
, CONSTRAINT [CIX_Table_TableID] UNIQUE CLUSTERED ([SourceID] ASC, [TableID] ASC) ON psSourceID(SourceID)
)
ON psSourceID(SourceID)
GO
ALTER TABLE [dbo].[Table] SET (LOCK_ESCALATION = AUTO)
GO
The TRUNCATE
command is being blocked by a session running updates against the table. In lower environments a blocking process was never hit after many trials so the assumption was that WITH PARTITION
would only place meta data locks by partition, not the entire table.