Comments (13)
还有疑问发新贴
from sqlsugar.
只更新不插入 可以用
db.Fastest().BulkUpdate(GetList())//更新
from sqlsugar.
有这个功能
from sqlsugar.
要插入+更新的
透過Storage來處理有上述疑慮(1.要遍歷資料表, 2.有鍵值重複損壞資料表的風險)
所以才發這個issue討論
from sqlsugar.
另外一個衍生議題
Fastest.BulkCopy這個功能也是沒鍵值檢查的話有損壞資料表的風險
如果要確保BulkCopy的絕對不會有問題, 一樣要在BulkCopy前遍鎖表並遍歷鍵值
BulkCopy結束後才解鎖資料表
是否能評估安全版本?
方案是:
- 建立暫存表
- BulkCopy到暫存表
- 如果沒有事務則開啟局部事務
- select into 到主表
- 如果局部事務存在則提交與關閉
- 刪除暫存表
from sqlsugar.
db.BeginTran();
db.Storageable(getAll)
.TranLock()//启用锁
.ExecuteSqlBulkCopy();
db.CommitTran();
from sqlsugar.
SqlSugarCore 5.1.4.108-preview02 升级到这个版本 对于 PageSize(1000)也支持了锁以前不支持的
from sqlsugar.
db.BeginTran();
//TranLock使用行锁
db.Storageable(new Order() { Id=1, Name="jack" }).TranLock().PageSize(1000).ExecuteSqlBulkCopy();
db.CommitTran();
from sqlsugar.
是這樣的, Oracle不支持BulkCopy事務
再加上鍵值檢查
如有其他程式也正在寫入
撈取的鍵值有可能是舊的
才有了這次的提議
整理一下提議:
- Fastest.BulkMerge 支持
- Fastest.BulkCopy的Safe模式支持
思路跟BulkUpdate現有的實作是一樣的:
- 透過BulkCopy將資料塞入暫存表
- 透過Merge或Insert Into select語法將資料塞回主表
提議好處:
- 大型資料表(千萬級)插入大資料, 不需將資料撈到程式中確認鍵值是否已存在
- 即使BulkCopy不檢查約束也不會導致主表損壞不可用(以Oracle為例, 直接BulkCopy表會導致鍵值重複, 使表不可用)
- 對不支持BulkCopy事務的資料庫, 也可以將事務在Merge或Insert Into select的階段處理, BulkCopy放在事務外
- 有任何錯誤會先發生在暫存表, 不會對主表產生影響
您再評估看看有沒有納入庫的價值, 謝謝
from sqlsugar.
原来如此,目前还真只有oracle bulkcopy不支持外部事务,研究一下
from sqlsugar.
SqlSugarCore 5.1.4.109-preview02 已支持了
db.Fastest<UnitaafdsTest>() .BulkMerge(list2);
from sqlsugar.
列新到最新预览版本就行了
from sqlsugar.
至于 Fastest.BulkCopy的Safe 文档有修复方案 或者你直接用
SqlSugarCore 5.1.4.109-preview02 已支持了
db.Fastest<UnitaafdsTest>() .BulkMerge(list2);
from sqlsugar.
Related Issues (20)
- Aop 不支持通过 Ado 直接执行 sql 语句使用记录日志,有地方全局配置吗? HOT 5
- 如何让Select预先处理再进行查询 HOT 25
- 描误信息: intemal Error 堆钱信息: at 0raclelntemal.TTC.TTCExecuteSal.ReceiveExecuteResponse HOT 4
- 大佬 MAUI Release第一次 访问数据库会抛出这个错误。(Debug没有这个错误)
- Updateable一起使用 WhereColumns和UpdateColumns好像有错误 HOT 3
- IsAutoRemoveDataCache相關問題 HOT 4
- How to retrieve data from a SplitTable and join it with an SQL function [dbo].fn_ListDayOfMonth HOT 3
- Exception in {"Index was outside the bounds of the array."} When use Join three table HOT 5
- Is there any way to optimize this command? HOT 10
- Illegal mix of collations HOT 3
- 如何在 SqlSugar 中集成 CAP HOT 3
- Oracle中INTERVAL DAY TO SECOND数据类型映射TimeSpan, OracleDbBind中MappingTypesConst中应为timespan HOT 3
- If we use IList<T> for Storageable/Insertable/Updatable, sometime may face Newtonsoft.Json.JsonSerializationException HOT 2
- 多个DB的问题 HOT 3
- sqlserver数据查询的问题 HOT 2
- WhereClassByPrimaryKey參數前後綴過長 HOT 2
- InsertOrUpdate()函数插入更新遇到的问题 HOT 2
- Operand type clash: time is incompatible with float HOT 1
- Insert Other Flied DateTime.Now Bug Insert => '2024-01-1613:00:00.000' HOT 9
- The most industrious open-source project globally, resolving issues at the fastest pace.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlsugar.