duckdb benchmark, csv vs parquet vs native table
Small benchmark i did today with duckdb, nothing scientific, i just curious how slow csv really is for lookup query. I have skip-trace data, one column is phone number, and i want to find one number. Same query every time, only the format change.
select "PH: Phone1" from <source> where "PH: Phone1" = 6173353940;
Result from my laptop:
read_csv_auto('input.csv') real 0.925s
read_parquet('skip-trace.parquet') real 0.016s
skip_trace (native duckdb table) real 0.008s
skip_trace after create index real 0.002s

The full session if you want to see it, including the create index:
$ duckdb skip-trace
D select "PH: Phone1" from read_csv_auto('input.csv') where "PH: Phone1" = 6173353940;
Run Time (s): real 0.925
D select "PH: Phone1" from read_parquet('skip-trace.parquet') where "PH: Phone1" = 6173353940;
Run Time (s): real 0.016
D select "PH: Phone1" from skip_trace where "PH: Phone1" = 6173353940;
Run Time (s): real 0.008
D create index idx_phone_1 on skip_trace("PH: Phone1");
Run Time (s): real 0.069
D select "PH: Phone1" from skip_trace where "PH: Phone1" = 6173353940;
Run Time (s): real 0.002
What i take from this:
- csv lose badly, almost 60x slower than parquet for same query. Duckdb must parse the text again every time, no surprise there but i still surprise how big the gap is.
- parquet alone already very good, 0.016s with zero setup. This is why everybody use it for data work.
- native table a bit faster than parquet, but not much, for one query like this the difference is small.
- index bring it down to 0.002s and the index only take 0.069s to build. If you query same column over and over, do it.
- funny detail, duckdb cli show my phone number as “6.17 billion” under the value, first time i see a phone number displayed like that.
One caveat, this is one query on one machine, not a real benchmark suite. But i do this kind of lookup all day on skip-trace data, and the order of magnitude is consistent every time, so i stop bothering with csv after import.
- [ ] Ref: https://duckdb.org/docs/data/csv/overview
- [ ] Ref: https://duckdb.org/docs/stable/sql/indexes