sqlite insert taking long time

梦想与她 提交于 2019-12-21 22:16:52

问题


I'm inserting just short of 200,000 rows into an sqlite database table. I'm just using a very plain .sql file via sqlite3 in terminal. I'd bet it's been running for at least 30 minutes. Is this normal or should I shut the process down and try something differently?


回答1:


Insert speed in sqlite mainly depends on:

  • amount of inserts per transaction (insert without transaction is an atomic insert, each in it's own transaction, which means it's very slow)
  • database mode - WAL or normal journal
  • number of indexes on the inserted fields
  • disk speed

If speed is a problem, then you should consult google for each of those factors I wrote and act appropriately.




回答2:


You should be doing bulk inserts, the kind where you specify the values in a big list, rather than inserting one row at a time. Like this: SQL Bulk Insert statement



来源:https://stackoverflow.com/questions/14787943/sqlite-insert-taking-long-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!