先给大家拜个早年了。祝愿虎年都虎头虎脑的。问题: 4个源数据表s1,s2,s3,s4, 一个目标表 d1, 写了个过程usp, insert into d1 select * from @s, 因为数据量都在100W 级别上,单独执行需要十分钟左右,所以需要并行执行usp @s=s1, usp @s=s2, usp @s=s3, usp @s=s4, 就造成死锁, d1 有索引,s1-4无索引。 请教该如何优化?
Transaction (Process ID 94) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
Transaction (Process ID 94) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
要不你上PK索引,同時建立機制確保PK or unique唯一性
再看看會不會出這個問題呢?
to foren_whb : 如果bulk insert 就好了, 可以考虑。
疑问: 如果将目标d1 建立分区表, 是否可以并行?
比較常見的就是存在PK,然後並發匯入了同PK的資料
如果你沒有PK,或者在匯入數據源前能夠保證絕對不會觸發PK or unique衝突
問題就不大啦
- -時間充裕,你就先把所有表的數據匯入沒有任何索引的中轉臨時表中
完成匯入后,再過濾,再從中轉表統一匯入你的目標表中
这是什么
rucypli, 就是并行执行usp,不好意思, 没写清楚。
加载速度非常快 < 1 秒,但不是对所有的问题都适用。(比如主键,唯一键 等等问题)看看分区表的使用
给你个参考:去google 查找:SQL Server 2005 分区表滑动窗口方案实践。SQL 分区表分区切换。滑动窗口。