News for hackers. Stuff that matters.
Re:DuckDB Isn't Just Fast by LunaSea on Tuesday June 11, 2024 @07:46AM (#40645100)
Quick example:

``` COPY ( SELECT DISTINCT ON (b, c) * FROM READ_PARQUET('input.parquet') ORDER BY a DESC ) TO 'output.parquet' ( FORMAT PARQUET, COMPRESSION 'ZSTD' ) ; ```

Where the input file has 25M rows (500Mb in Parquet format) containing 4 columns, a and b are BIGINTs and c and d are VARCHARs.

On a Mac Book Pro M1 with 8GB of RAM (16x the original file size), the query will not finish.

This is a query that could very easily be optimised to take little amounts of space (hash the DISTINCT ON key, and replace in-place the already seen values if the value of "a" is larger than the one that already exists.)

Re:DuckDB Isn't Just Fast by belter on Tuesday June 11, 2024 @10:17AM (#40646428)
With the information in your example... I created a parquet file with 50 million rows, random data, same data types. Parquet file is 391 MB on disk (NTFS)

Query will complete, but in aprox 3,5 to 4 min, you will need up to 14 GB of memory. (4 Core, Win10, 32GB RAM).

You can see below, memory usage in MB, throughout the query, sampled at 15 sec interval.

  duckdb      321.01 -> Start Query
  duckdb     6302.12
  duckdb    13918.04
  duckdb    10963.74
  duckdb     8586.76
  duckdb     7613.86
  duckdb     6749.53
  duckdb     5990.96
  duckdb     5293.35
  duckdb     4205.53
  duckdb     3153.59
  duckdb     1482.86
  duckdb      386.29 -> End Query
So yes, there are some opportunities for optimization here :-)
Re:DuckDB Isn't Just Fast by LunaSea on Tuesday June 11, 2024 @12:34PM (#40648323)
Thanks for the benchmarks! :)

Indeed, 14GB seems really high for a 400MB Parquet file, that's a 35x multiple on the base file size.

Of course, the data is compressed on disk, but even the uncompressed data isn't that large so I believe indeed that quite a lot of optimisations are still possible.

Re:DuckDB Isn't Just Fast by wenc on Tuesday June 11, 2024 @05:30PM (#40651764)
It’s also the aggregation operation. If there are many unique groups it can take a lot of memory.

Newer DuckDbs are able to handle out of core operations better. But in general just because data fits in memory doesn’t mean the operation will — and as I said 8GB is very limited memory so it will entail spilling to disk.

https://duckdb.org/2024/03/29/external-aggregation.html

Re:DuckDB Isn't Just Fast by wenc on Tuesday June 11, 2024 @11:30AM (#40647418)
What is the error message you’re getting? Or is it simply that the query will not finish? (Does it continue to run?)

Parquet files are compressed, and many analytic operations require more memory than the on disk size. When you don’t have enough ram DuckDb has to switch to out of core mode which is slower. (It’s the classic performance trade off)

8gb of ram is not enough usually to expect performance from analytic operations - I usually have minimum 16. My current instance is remote which has 256gb ram. I never run out of ram and DuckDb never fails and runs super fast.