Live data from Hacker News

Inserting a billion rows in SQLite under a minute

avi.im

1–10 of 164 posts

Re: Inserting a billion rows in SQLite under a minute

#4
You 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

#5
I wonder if something like https://paulbradley.org/sqlite-test-data/ could be used to generate the test data in sqlite3 directly, and if it would be any faster.

(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

#7
post #4

You 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.

Are you suggesting have a template and then updating rows with random values where necessary?

Re: Inserting a billion rows in SQLite under a minute

#9

If it's single, in memory table, is there really need to use database? Won't language provided data structures suffice?

It is a good question, but I'm guessing that the whole reason for creating the database in the first place is to test interactions with the database, in which case you'd have to mock up all the interactions being tested (selects, deletes, joins, etc.).

Re: Inserting a billion rows in SQLite under a minute

#10
Creator of RediSQL / zeeSQL (https://zeesql.com/)

Insertion 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...

;)

Post reply on HN