SQLite 的一个事务中可以完成多少次插入? [英] How many inserts can be done within one transaction in SQLite?
问题描述
我正在尝试向 SQLite 数据库中插入大量记录(以数百万计).从文件流 (C++) 中读取数据.如果我开始一个事务,执行所有的插入,然后提交事务,我只会得到非常少的记录实际插入到我的数据库中.
I'm trying to insert a large amount of records (in the millions) into an SQLite database. The data is read in from a file stream (C++). If I begin a single transaction, perform all of the inserts and then commit the transaction, I only get a very small percentage of records actually inserted in my database.
插入的那些看起来是随机的——我真的看不出任何模式,哪些被插入,哪些被遗漏.但是,如果我提交然后在 2000 次插入之后再次开始事务,我就不会遇到这个问题并且所有记录都被插入,即使这个过程慢得多.所以...
The ones that are inserted seem random -- I can't really see any pattern for which ones do get inserted and which ones get left out. However, if I commit and then begin the transaction again after something like 2000 inserts, I don't have this problem and all of the records are inserted, even though the process is much slower. So...
对一个事务中可以完成的插入次数有严格限制吗?有没有办法改变这个限制?
Is there a strict limit to how many inserts can be done within one transaction? Is there a way to change this limit?
推荐答案
我能够在单个事务中插入 1000 万行而不会出现问题.
I am able to insert 10 millions rows in a single transaction without a problem.
我的猜测:
- 您在单个语句中插入了太多行并达到了表达式树的最大深度限制.这可以完全关闭.
- 您正在使用过长的 INSERT,没有绑定值并且达到 SQL 语句的最大长度限制.在这种情况下,请使用参数绑定.
- 这可能是库中的一个错误(您是否检查每个 API 返回的错误代码?)
检查 SQLite 中的限制.如果您展示如何在代码中准备和执行 INSERT,可能会有所帮助.
Check Limits In SQLite. It may help if you show how you prepare and execute INSERTs in the code.
这篇关于SQLite 的一个事务中可以完成多少次插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!