Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many inserts can be done within one transaction in SQLite?

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.

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?

like image 966
Tricky Avatar asked Aug 26 '11 02:08

Tricky


People also ask

How many entries can SQLite handle?

When used with the maximum page size of 65536, this gives a maximum SQLite database size of about 281 terabytes. The max_page_count PRAGMA can be used to raise or lower this limit at run-time. The theoretical maximum number of rows in a table is 264 (18446744073709551616 or about 1.8e+19).

What are the limits of SQLite?

An SQLite database is limited in size to 281 terabytes (248 bytes, 256 tibibytes). And even if it could handle larger databases, SQLite stores the entire database in a single disk file and many filesystems limit the maximum size of files to something less than this.

Does SQLite support bulk insert?

SQLite doesn't have any special way to bulk insert data. To get optimal performance when inserting or updating data, ensure that you do the following: Use a transaction. Reuse the same parameterized command.

How much data is too much for SQLite?

SQLite database files have a maximum size of about 140 TB. On a phone, the size of the storage (a few GB) will limit your database file size, while the memory size will limit how much data you can retrieve from a query. Furthermore, Android cursors have a limit of 1 MB for the results.


1 Answers

I am able to insert 10 millions rows in a single transaction without a problem.

My guesses:

  • you are inserting too much rows in a single statement and hitting Maximum Depth Of An Expression Tree limit. This can be switched off completely.
  • you are using overly long INSERTs without binding values and hitting Maximum Length Of An SQL Statement limit. In this case, use parameter binding.
  • it may be a bug in the library (are you checking every API return for error codes?)

Check Limits In SQLite. It may help if you show how you prepare and execute INSERTs in the code.

like image 105
hamstergene Avatar answered Sep 22 '22 05:09

hamstergene