Inserting a billion rows in SQLite under a minute
1–10 of 164 posts
Re: Inserting a billion rows in SQLite under a minute
#2I wonder how much I could speed up my test suites (that don't rely on transaction rollbacks) by disabling journalling. Those milliseconds per query add up to seconds per tests and minutes per PR.
Re: Inserting a billion rows in SQLite under a minute
#3INSERT INTO t (...) SELECT ... from virtual_table
would be any faster.
Re: Inserting a billion rows in SQLite under a minute
#4We do SQL evaluation for a lot of business logic throughout our product, and we have found that starting from a template database (i.e. one with the schema predefined and canonical values populated) can save a lot of time when working in tight loops.
Re: Inserting a billion rows in SQLite under a minute
#5(It would likely be faster for other DB engines, because there is network overhead in the communication between the program and the DB; no such things for sqlite).
Re: Inserting a billion rows in SQLite under a minute
#6Re: Inserting a billion rows in SQLite under a minute
#7You can go even faster if you can organize your problem such that you simply start from a copy of a template SQLite database each time (it is just a file/byte sequence). We do SQL evaluation for a lot of business logic throughout our product, and we have found that starting from a template database (i.e. one with the schema predefined and canonical values populated) can save a lot of time when working in tight loops.
Re: Inserting a billion rows in SQLite under a minute
#8Re: Inserting a billion rows in SQLite under a minute
#9If it's single, in memory table, is there really need to use database? Won't language provided data structures suffice?
Re: Inserting a billion rows in SQLite under a minute
#10Insertion performance on a single table are very very hard to optimize.
A single process looping it is your best bet.
I would just increase the batch size, which is the most influent factor.
Then another point... When you do batches, you do
BEGIN TRANSACTION;
for i in range(1, 50):
execute_stmt
COMMIT;
You do not create a long list of parameters.https://github.com/avinassh/fast-sqlite3-inserts/blob/master...
;)