






















April 18, 2026, 9:15pm 1
I have a rust program that reads a CSV file (approx 3000 rows with 5 pieces of data / row) and inserts it into an SQLite database. Currently I have one function that reads the CSV into a vector of structures and a second function that takes the vector and writes it to an SQLite database. It works. Does it make more sense to write the data to the SQL database as it is being read from the CSV file i.e. record by record, eliminating the need to create a large vector of structures?
mroth April 18, 2026, 9:34pm 2
It depends. It depends on your requirements. Only the requirements.
So ask yourself a few questions:
Most importantly: what do you need now?
In this context, “now” could mean this week, this month, or this year. It depends on the environment your program runs in.
kpreid April 18, 2026, 9:39pm 3
There are various factors which can affect whether one or the other is more efficient, and it's difficult to say without taking measurements.
Ways writing all the records at once can be more efficient:
Ways writing the records one at a time can be more efficient:
A frequently useful compromise between these modes of operation is to pick a number of records to be your buffer size, and read only up to that many records before switching to writing. However, before considering complicating things this way, you should measure the performance of both of the basic strategies, on large files and small files.
1 Like
mroth April 18, 2026, 9:48pm 4
It is true. Depending on whether Write-Ahead Logging is enabled, the difference can be enormous.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。