简体   繁体   English

使用Perl API使SQlite3插入更快

[英]Making SQlite3 inserts faster using Perl API

I am DBD::SQLite to insert some data in SQlite3 db using perl. 我是DBD :: SQLite,使用perl在SQlite3 db中插入一些数据。

I have noticed that it takes a lot of time to insert(inserting 35k rows). 我注意到插入(插入35k行)需要花费很多时间。 Is there any way to make it faster. 有没有办法让它更快。

Optimization is important for me rather than data sync. 优化对我而言非常重要,而不是数据同步。 How can i optimize it using perl? 我如何使用perl优化它?

Please help. 请帮忙。

Try executing this statement before doing your inserts: 在进行插入之前尝试执行此语句:

PRAGMA synchronous = OFF

See the SQLite documentation for more information . 有关更多信息,请参阅SQLite文档。

Also, as Ilion notes, try to prepare() the statement just once and then re- execute() multiple times with different bind values. 此外,正如Ilion所说,尝试只prepare()一次语句prepare() ,然后使用不同的绑定值重复execute()多次。 Turning off AutoCommit and then explicitly committing only every N rows inserted may also help, for some values of N. 对于某些N值,关闭AutoCommit然后显式提交仅插入的每N行也可能有所帮助。

Make sure you are using prepared statements so it doesn't have to analyze each insert. 确保使用预准备语句,因此不必分析每个插入。 Also try grouping your insert statements by surrounding them with Begin ... Commit as described in this FAQ . 还可以尝试将insert语句分组,方法是使用Begin ... Commit ,如本FAQ中所述

Make sure you have AutoCommit => 0 set on your connection. 确保在连接上设置了AutoCommit => 0 Insteed, commit explicitly after every batch of inserts. Insteed,在每批插入后明确提交。

Beside turning auto-commit off altogether, you can also try using a large transaction. 除了完全关闭自动提交之外,您还可以尝试使用大型事务。 Makes all the difference to single-row inserts, usually. 通常,对单行插入有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM