一堆插入(事务)比单独插入要快
一堆插入(事务)比每个单独插入更快,我认为是这样,也许不是,告诉我谁检查,是否有区别,也许表上有很多索引。
Bunch of Inserts (transaction) is quicker than each insert separately, i think so, maybe not, tell me who check, is there a difference, maybe if many indexes on a table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,MS SQL Server 在事务保护中执行所有更新,以确保数据库文件的完整性。如果您不手动处理事务,则每个语句将变成一个自己的事务。如果您正在进行大量小更新,则打开和关闭隐式事务的开销可能会导致性能损失。
As far as I know MS SQL Server does all updates within transaction protection to ensure integrity of the database files. If you do not handle transactions manually, each statement will turn into an own transaction. If you are doing a lot of small updates the overhead of opening and closing the implicit transactions might be causing the performance penality.
单个事务中是一次插入还是多次插入并不重要。在没有事务的情况下进行插入并不能真正改变这一点。
然而,在该表上插入大量带有活动索引的数据将使运行速度比您希望的慢。在这种情况下,我建议禁用索引并进行批量插入,然后在完成后重新启用索引。
It doesn't really matter if there's one insert or many inserts within a single transaction. Doing inserts without a transaction doesn't really change that.
However inserting huge amounts with active indexes on that table will make things run slower than what you might like. In that case I suggest disabling the index and doing a bulk insert and reenabling the index after you're done.
如果您使用的是功能齐全的数据库引擎(例如 SQL Server),那么它将为您处理事务:隐形。但是,如果您想在 FireDB、SQLite 或 Hypersonic 等上运行代码,那么您需要采取在应用程序中手动滚动事务的方法。您会注意到主要在插入和更新方面的差异。
If you are using a fully featured database engine like SQL Server, then it will handle transactions for you: invisibly. But, if you want to run your code on something like FireDB, SQLite, or Hypersonic, then you'll need to take an approach of manually rolling transactions in your app. You'll notice the difference mostly on inserts and updates.