表分區(qū)的一個好處:能夠避免Deadlock,分區(qū)之間是相互獨立的,對一個分區(qū)加X鎖,不會對其他分區(qū)產生contention。
創(chuàng)新互聯(lián)主營鄱陽網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,成都app軟件開發(fā),鄱陽h5小程序制作搭建,鄱陽網(wǎng)站營銷推廣歡迎鄱陽等地區(qū)企業(yè)咨詢
在項目中,有如下 Partition Function 和 Partition Scheme
CREATE PARTITION FUNCTION [funcPartition_int_DataSourceID](int) AS RANGE LEFT FOR VALUES (1, 2, 3)CREATE PARTITION SCHEME [schePartition_int_DataSourceID] AS PARTITION [funcPartition_DataSourceID] TO ([PRIMARY], [PRIMARY], [PRIMARY], [PRIMARY])create table dbo.dt_test ( ...More column definition DataSourceID int)on [schePartition_int_DataSourceID](DataSourceID)
查看ETL的execution log,有時會發(fā)現(xiàn) Deadlock Issue,對相關package Troubleshooting發(fā)現(xiàn),發(fā)生deadlock的root cause是:同時更新表的兩條語句產生contention,導致deadlock。仔細check代碼,更新的兩條查詢語句都使用Partition Column(DataSourceID) 作為過濾條件。我推測,可能是這兩個DataSourceID位于同一個Partition。
1,驗證boundary value
select prv.function_id,pf.name,pf.boundary_value_on_right,prv.value as BoundaryValuefrom sys.partition_range_values prvinner join sys.partition_functions pf on prv.function_id=pf.function_idwhere pf.name='funcPartition_int_DataSourceID'
BoundaryValue的值小于當前 DataSourceID的最大值,產生 contention的兩個DataSourceID 在最右邊的partition中。
隨著項目數(shù)據(jù)的增加和人員的更替,缺少合理的管理計劃,導致額外增加的DataSourceID都被分配到同一個partition中。
2,創(chuàng)建Job,自動分區(qū)
最佳實踐,如果一個partition是non-empty,那么split range會導致data movement,這可能是一個非常耗費IO的一個process,為了避免extensive data movement,最好是預留一個empty partition,每次都從empty partition 中split range。
use db_studygodeclare @CurrentMaxBoundaryValue intdeclare @ExistingMaxDataSourceID intdeclare @BoudaryValue intselect @ExistingMaxDataSourceID = max(dds.DataSourceID)from dbo.dt_DataSource dds with(nolock)select @CurrentMaxBoundaryValue= max(cast(prv.value as int))from sys.partition_functions pf inner join sys.partition_range_values prv on pf.function_id=prv.function_idwhere pf.name='funcPartition_int_DataSourceID'-- add new boundary valueif @CurrentMaxBoundaryValue<@ExistingMaxDataSourceID+1begin set @BoudaryValue=@CurrentMaxBoundaryValue+1 DECLARE @SQL NVARCHAR(MAX)=N'ALTER PARTITION SCHEME [schePartition_int_DataSourceID] NEXT USED [PRIMARY] ALTER PARTITION FUNCTION [funcPartition_int_DataSourceID]() SPLIT RANGE (' declare @ExecSql nvarchar(max) set @ExecSql='' while @BoudaryValue<=@ExistingMaxDataSourceID+1 BEGIN SELECT @ExecSql = @SQL+ cast(@BoudaryValue as varchar(10))+ N')' EXEC(@ExecSql) set @BoudaryValue=@BoudaryValue+1 endend
本例將分區(qū)全部存放在Primary FileGroup, 如果需要將不同的Partition存儲在不同的FileGroup,那么可以增加Create filegroup的代碼。
3,在Job執(zhí)行時,Issue an error
Executed as user: NT SERVICE\SQLSERVERAGENT. UNKNOWN TOKEN failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations. [SQLSTATE 42000] (Error 1934). The step failed.
QUOTED_IDENTIFIER設置錯誤,添加下面的script,即可
SET QUOTED_IDENTIFIER ON
參考:SET QUOTED_IDENTIFIER (Transact-SQL)
SET QUOTED_IDENTIFIER must be ON when you are creating or changing indexes on computed columns or indexed views. If SET QUOTED_IDENTIFIER is OFF, CREATE, UPDATE, INSERT, and DELETE statements on tables with indexes on computed columns or indexed views will fail.
SET QUOTED_IDENTIFIER must be ON when you are creating a filtered index.
SET QUOTED_IDENTIFIER must be ON when you invoke XML data type methods.
分享題目:自動管理分區(qū)
瀏覽路徑:http://aaarwkj.com/article40/iihhho.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、網(wǎng)頁設計公司、企業(yè)建站、云服務器、網(wǎng)站導航、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)