Giter Site home page Giter Site logo

Comments (13)

DotNetNext avatar DotNetNext commented on June 6, 2024 2

还有疑问发新贴

from sqlsugar.

DotNetNext avatar DotNetNext commented on June 6, 2024

只更新不插入 可以用
db.Fastest().BulkUpdate(GetList())//更新

from sqlsugar.

DotNetNext avatar DotNetNext commented on June 6, 2024

有这个功能

from sqlsugar.

Yumitoya8569 avatar Yumitoya8569 commented on June 6, 2024

要插入+更新的
透過Storage來處理有上述疑慮(1.要遍歷資料表, 2.有鍵值重複損壞資料表的風險)
所以才發這個issue討論

from sqlsugar.

Yumitoya8569 avatar Yumitoya8569 commented on June 6, 2024

另外一個衍生議題
Fastest.BulkCopy這個功能也是沒鍵值檢查的話有損壞資料表的風險
如果要確保BulkCopy的絕對不會有問題, 一樣要在BulkCopy前遍鎖表並遍歷鍵值
BulkCopy結束後才解鎖資料表

是否能評估安全版本?
方案是:

  1. 建立暫存表
  2. BulkCopy到暫存表
  3. 如果沒有事務則開啟局部事務
  4. select into 到主表
  5. 如果局部事務存在則提交與關閉
  6. 刪除暫存表

from sqlsugar.

DotNetNext avatar DotNetNext commented on June 6, 2024
 db.BeginTran();
  db.Storageable(getAll)
.TranLock()//启用锁
.ExecuteSqlBulkCopy();
 db.CommitTran();

from sqlsugar.

DotNetNext avatar DotNetNext commented on June 6, 2024

SqlSugarCore 5.1.4.108-preview02 升级到这个版本 对于 PageSize(1000)也支持了锁以前不支持的

from sqlsugar.

DotNetNext avatar DotNetNext commented on June 6, 2024

db.BeginTran();
//TranLock使用行锁
db.Storageable(new Order() { Id=1, Name="jack" }).TranLock().PageSize(1000).ExecuteSqlBulkCopy();

db.CommitTran();

from sqlsugar.

Yumitoya8569 avatar Yumitoya8569 commented on June 6, 2024

是這樣的, Oracle不支持BulkCopy事務
再加上鍵值檢查
如有其他程式也正在寫入
撈取的鍵值有可能是舊的
才有了這次的提議

整理一下提議:

  1. Fastest.BulkMerge 支持
  2. Fastest.BulkCopy的Safe模式支持

思路跟BulkUpdate現有的實作是一樣的:

  1. 透過BulkCopy將資料塞入暫存表
  2. 透過Merge或Insert Into select語法將資料塞回主表

提議好處:

  1. 大型資料表(千萬級)插入大資料, 不需將資料撈到程式中確認鍵值是否已存在
  2. 即使BulkCopy不檢查約束也不會導致主表損壞不可用(以Oracle為例, 直接BulkCopy表會導致鍵值重複, 使表不可用)
  3. 對不支持BulkCopy事務的資料庫, 也可以將事務在Merge或Insert Into select的階段處理, BulkCopy放在事務外
  4. 有任何錯誤會先發生在暫存表, 不會對主表產生影響

您再評估看看有沒有納入庫的價值, 謝謝

from sqlsugar.

DotNetNext avatar DotNetNext commented on June 6, 2024

原来如此,目前还真只有oracle bulkcopy不支持外部事务,研究一下

from sqlsugar.

DotNetNext avatar DotNetNext commented on June 6, 2024

SqlSugarCore 5.1.4.109-preview02 已支持了

    db.Fastest<UnitaafdsTest>() .BulkMerge(list2);

from sqlsugar.

DotNetNext avatar DotNetNext commented on June 6, 2024

列新到最新预览版本就行了

from sqlsugar.

DotNetNext avatar DotNetNext commented on June 6, 2024

至于 Fastest.BulkCopy的Safe 文档有修复方案 或者你直接用

SqlSugarCore 5.1.4.109-preview02 已支持了

db.Fastest<UnitaafdsTest>() .BulkMerge(list2);

from sqlsugar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.