Sql server 使用对齐索引更新分区表会锁定所有分区
部分功能和模式:Sql server 使用对齐索引更新分区表会锁定所有分区,sql-server,sql-server-2008-r2,sql-server-2012,database-partitioning,Sql Server,Sql Server 2008 R2,Sql Server 2012,Database Partitioning,部分功能和模式: CREATE PARTITION FUNCTION SegmentPartitioningFunction (smallint) AS RANGE LEFT FOR VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) ; GO CREATE PARTITION SCHEME SegmentPartitioningSchema AS PARTITION SegmentPartitioningFunction ALL TO ([PRIMA
CREATE PARTITION FUNCTION SegmentPartitioningFunction (smallint)
AS RANGE LEFT FOR VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) ;
GO
CREATE PARTITION SCHEME SegmentPartitioningSchema
AS PARTITION SegmentPartitioningFunction ALL TO ([PRIMARY])
GO
PartTable
(
prd_id int,
cat_id smallint,
datacolumn smallint,
primary key (prd_id, cat_id) on SegmentPartitioningSchema(cat_id)
) on SegmentPartitioningSchema(cat_id)
我有一张桌子(注意桌子是M:N):
CREATE PARTITION FUNCTION SegmentPartitioningFunction (smallint)
AS RANGE LEFT FOR VALUES (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) ;
GO
CREATE PARTITION SCHEME SegmentPartitioningSchema
AS PARTITION SegmentPartitioningFunction ALL TO ([PRIMARY])
GO
PartTable
(
prd_id int,
cat_id smallint,
datacolumn smallint,
primary key (prd_id, cat_id) on SegmentPartitioningSchema(cat_id)
) on SegmentPartitioningSchema(cat_id)
注意:我尝试了所有3种组合(part.table
,part.index
,part.table和index
)
此外,我有一个关于PRD_ID
和CAT_ID
的索引,它们是外键
我使用此选择将LOCK\u ESCALATION
设置为AUTO
确认:
SELECT lock_escalation_desc FROM sys.tables
现在,我想做的是,通过我的理解,应该可以做到:
begin tran
update PartTable set DataColumn = DataColumn where cat_id = 1
-- commit tran -- this doesnt happen yet
同时在不同的连接中
begin tran
update PartTable set DataColumn = DataColumn where cat_id = 2
-- commit tran -- this doesnt happen yet
执行计划
巴斯德宾:
奖金问题:为什么使用顶级操作员
根据我的理解,我应该在分区上获得IX
锁,同时只能获得一个分区,这意味着两个事务可以同时完成,第二个事务cat_id=2
不必等待第一个,因为表和索引都是分区的,索引是对齐的
然而,这并没有发生,当我检查执行计划时,我发现表扫描在每个分区上都会发生,即使这对我来说没有意义
我尝试了technet
,文档
和stackoverflow
,但都没有找到答案。
现在我知道PK
应该是CAT\u ID
,PRD\u ID
(这使得表格的使用方式更有意义)
我目前正在使用SQLServer2012
,但我认为它应该比2008R2
工作得更好。您可以将更新的实际(!)执行计划发布为XML(pastebin)吗?我不明白这为什么行不通。我希望锁升级到X锁分区。您能将更新的实际(!)执行计划发布为XML(pastebin)吗?我不明白这为什么行不通。我希望锁升级到X锁分区。