News for hackers. Stuff that matters.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by simonw on Saturday September 19, 2020 @11:42PM (#24531732)
I spent a while looking at this today. It's really interesting.

It's not based on SQLite at all (except for borrowing the SQLite shell implementation) but it looks very much like SQLite, in particular:

- It's designed to work as an embedded library, eliminating the network overhead you usually get when talking to a database

- Each database is a single file on disk

- It ships as an "amalgamation" build - a single giant C++ file (SQLite is a single giant C file)

Impressively, if you run "pip install duckdb" it Just Works - you can then "import duckdb" and start using it, with an interface that looks very similar to the sqlite3 module that ships with Python.

The key reason this exists is that it's a column store, with vectorized operations across columns - making it ideal for analytical workloads. This blog entry has some benchmarks that illustrate how well it works in that regard: https://uwekorn.com/2019/10/19/taking-duckdb-for-a-spin.html

It's also backed up by some strong computer science. It's by the academic researchers behind MonetDB and includes implementations of a bunch of interesting papers: https://duckdb.org/docs/why_duckdb#standing-on-the-shoulders...

It's a really interesting piece of software, and unlike many other "new databases" it feels like it fills a very genuine gap in my toolbox.

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by gijzelaerr on Sunday September 20, 2020 @02:37AM (#24532304)
And MonetDB took some inspiration back from DuckDB to develop an embedded version also:

https://github.com/MonetDBSolutions/MonetDBe-Python/

Disclaimer: i'm working on this.

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by Firerouge on Sunday September 20, 2020 @03:03AM (#24532389)
Could you elaborate on some of the similarities and differences between DuckDB and MonetDB?
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by mkersten on Sunday September 20, 2020 @04:19AM (#24532668)
Disclaimer: i am working on MonetDB and I established the CWI database architectures group

DuckDB is designed as an experimental system after heavy exposure to the technniques deployed in MonetDB (open-source), Hyper, and Vectorwise.

The properties of the embedded version of MonetDB can be found here https://monetdbe.readthedocs.io/en/latest/introduction.html#

Some difference between MonetDB and DuckDB can be found here https://monetdbe.readthedocs.io/en/latest/migrations.html

and the blogpost mentioned above is covered in https://twitter.com/MonetDB/status/1282412295235280901?s=20

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by webmobdev on Sunday September 20, 2020 @12:29PM (#24534939)
If everything you said is accurate, somebody should make another pitch for WebSQL ( https://en.wikipedia.org/wiki/Web_SQL_Database ) with a custom version of DuckDb!

Every browser maker was interested in implementing it but the W3C couldn't go ahead with it because everyone chose to implement it using SQLite, where as W3C required more than one db back-end implementation to move forward.

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by wffurr on Sunday September 20, 2020 @12:42PM (#24535033)
Having sqlite included in all browsers with standard bindings would have been great.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by jansommer on Sunday September 20, 2020 @02:02PM (#24535846)
It would! But it would also be a security nightmare. Exploit SQLite and you could use it in Safari, Chrome and Firefox - everybody could be affected.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by andyfleming on Sunday September 20, 2020 @02:24PM (#24536046)
How would that be different from someone editing something in window.localStorage?
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by jansommer on Sunday September 20, 2020 @02:48PM (#24536284)
If that's all you need, it wouldn't make sense to include SQLite in the browser. If you're going to include a relational database you might as well use it
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by CRConrad on Sunday September 20, 2020 @03:58PM (#24536887)
I think that meant: How would that be more of a security nightmare than some malicious site editing your browser's whatever.localstorage?
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by hajile on Monday September 21, 2020 @09:20AM (#24543009)
Ironically, all the IndexDB implementations were just thin layers on top of sqlite last I checked.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by WorldMaker on Monday September 21, 2020 @05:52PM (#24548864)
The original slow IndexedDB implementations were done that way, but my understanding is that anything fast and "modern" probably isn't in 2020 as most of the browsers moved to their own IndexedDB storage implementations that are not SQLite-based. IndexedDB has very different expected performance characteristics than a pure relational DB (as it is a key/value store with indexes closer to most "NoSQL" DBs than to SQLite) and it did not (and does not) make long term sense to use SQLite below the hood.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by afiori on Monday September 21, 2020 @05:01AM (#24541233)
This could work if there is a subset of SQL where duckDB and SQLite behave almost identically
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by webmobdev on Tuesday September 22, 2020 @07:17PM (#24561153)
I often wondered why someone didn't do it with BerkleyDb too? I know Oracle owns it, but it is open source and someone like Mozilla could have implemented it in their browser just to get the W3C rolling on WebSQL.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by afiori on Wednesday September 23, 2020 @01:23AM (#24563277)
The problem with WebSQL would remain the same, it would be necessary to specify a subset of SQL as a web standard.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by Abishek_Muthian on Sunday September 20, 2020 @12:17AM (#24531855)
> - Each database is a single file on disk

Are these architecture independent? i.e. If I create the database on x86_64 and move it to ARM64; would it work seamlessly?

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by mytherin on Sunday September 20, 2020 @12:37AM (#24531921)
One of the authors here - portability of the storage is indeed one of our goals. We test that the same file can be loaded everywhere on different systems, including between ARM and x86.

I should mention the storage is still very much a work-in-progress. We are actively working on redesigning the storage to add compression and other extra features, meaning the storage format can change and be incompatible between different DuckDB versions. We plan to stabilize the storage format with V1.0, after which every subsequent DuckDB version should be able to read database files created by previous versions.

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by snthpy on Sunday September 20, 2020 @01:19PM (#24535407)
DuckDB looks very interesting and I'm quite excited to examine it more closely in the next few days!

I just wanted to add to the discussion that an unchanging file format, or at least a backwards compatible one, is a key feature of sqlite. See for example Richard Hipp's comments here [1] (I think he also mentioned earlier in the talk that the file format has become a limiting factor now in terms of some of the refactoring that they can do). The file format therefore seems likely to be a major factor in the long term success of this project and I am glad to see that you are taking your time before settling on any architecture here.

Given that you are targeting the data science and analytics space, what are your plans for integration with arrow and the feather file format? From a purely user/developer perspective, arrow's aim of shared memory data structures across different analytics tools, seems like a great goal. I know Wes McKinney and Ursa Labs have also spent quite some time at the file storage part of this, see for example the Feather V2 announcement [2].

What are your thoughts on the tradeoffs they considered and how do you see the requirements of DuckDB in relation to theirs?

From the Carnegie Mellon DuckDB talk [3], I saw that you already have a zero-copy reader to the pandas memory data structures, so the vision I have is that DuckDB could be the universal SQL interface to arrow datasets which can then also be shared with more complex ML models. Is that something that we can hope for or are there obstacles to this?

[1] https://youtu.be/Jib2AmRb_rk?t=3150

[2] https://ursalabs.org/blog/2020-feather-v2/

[3] https://www.youtube.com/watch?v=PFUZlNQIndo

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by mytherin on Sunday September 20, 2020 @01:51PM (#24535735)
Thanks for your detailed reply! As you mentioned - lessons learned by SQLite here are indeed crucial. We are very carefully trying to craft a storage format before fixing it in-place, specifically to try to avoid these problems. Backwards compatibility is a must, but backwards compatibility to a sane format is massively preferable :) No doubt we will end up making some mistakes in hindsight, though.

We already support reading from the arrow in-memory format [1], therefore it is already possible to use DuckDB to perform SQL-on-Arrow. More support there is definitely possible, and I think this is a very promising direction.

[1] https://github.com/cwida/duckdb/pull/866

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by snthpy on Monday September 21, 2020 @01:40AM (#24540178)
Thanks. That's great and I see you even support the new Arrow streaming model!
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by legg0myegg0 on Sunday September 20, 2020 @09:50PM (#24539017)
It's also possible to return a result set as an Arrow table, so round trip SQL on Arrow queries is possible (Arrow to DuckDB to Arrow)! It's not 100% zero-copy for strings, but it should work pretty well!
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by Abishek_Muthian on Sunday September 20, 2020 @12:46AM (#24531960)
Thanks for the confirmation on portability, I didn't see Go support in the home page; Is there an official Go driver support planned as well?
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by mytherin on Sunday September 20, 2020 @01:01AM (#24532005)
Neither Hannes nor me are very experienced with Go, so we are not the most suitable to do that. We do very much welcome external contributions, and someone did make a WIP go driver [1] in the past.

We also have a sqlite3 compatible C API that can be used to use DuckDB. This is actually how we use the sqlite3 shell: we directly use the sqlite shell but bind it to the duckdb library using this API. It might be possible to use the Go SQLite driver in a similar manner to talk to DuckDB.

[1] https://github.com/marcboeker/go-duckdb

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by sgt on Sunday September 20, 2020 @03:52AM (#24532570)
And Dart bindings? That could be really interesting for Flutter developers.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by StreamBright on Sunday September 20, 2020 @12:04PM (#24534747)
Do you consider (or maybe you already have) the advanced columnar features? Run length encoding, dictionary encoding, etc. It would be great to see how those perform under these workloads.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by mytherin on Sunday September 20, 2020 @01:46PM (#24535686)
Definitely. We have quite detailed plans for compression :) more to follow when we get to it.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by StreamBright on Sunday September 20, 2020 @02:43PM (#24536232)
Excellent! Thanks for the update.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by marton78 on Sunday September 20, 2020 @02:09AM (#24532218)
Couldn't you have used an already existing format for storage, e.g. Apache ORC?
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by mytherin on Sunday September 20, 2020 @05:06AM (#24532823)
Those formats have a different use case from a database system - they are mostly designed for write once, read many times workloads. As far as I’m aware you cannot update them in an ACID compliant manner, for example, which makes it difficult to use them as backend for an ACID database system.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by hfmuehleisen on Sunday September 20, 2020 @04:33AM (#24532704)
Another DuckDB developer here, we support reading table data from Parquet files directly.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by StreamBright on Sunday September 20, 2020 @12:06PM (#24534760)
I am a big fan of those formats but decoupling the actual storage features from the ecosystem is not a trivial task. I haven't look at the C++ version of ORC for a while but it used to be incomplete. Other than that, the solutions ORC uses to compress data is pretty amazing.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by brian_herman on Sunday September 20, 2020 @08:31AM (#24533628)
Yes, their testing folder is 26mb while their source code of the database is only 5.6mb. It looks like they took the same approach to testing as sqlite also.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by tmpz22 on Sunday September 20, 2020 @12:45AM (#24531956)
How might one go about using this in a language that’s not supported in the documentation such as golang?
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by mytherin on Sunday September 20, 2020 @01:13AM (#24532038)
Generally you would need to write bindings for the system. Experimental DuckDB bindings for Go do exist [1], however, they are rather old and might not work anymore.

We also have JDBC support, which might help for languages that know how to use that protocol. ODBC support is not implemented yet, but also planned.

We also have a SQLite-compatible C API [2], that can potentially be used to use an existing SQLite driver that uses the SQLite C API.

[1] https://github.com/marcboeker/go-duckdb

[2] https://github.com/cwida/duckdb/blob/master/tools/sqlite3_ap...

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by at6 on Sunday September 20, 2020 @09:25AM (#24533888)
Hi, author of the Go bindings here. I've just tested them and they are still working with the latest DuckDB version from master.
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by mytherin on Sunday September 20, 2020 @11:05AM (#24534449)
Excellent, thanks again for writing them :)
[dead]
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by Smerity on Sunday September 20, 2020 @12:26AM (#24531891)
A giant plant as in someone from their team planning this out and then planting this as a comment..?

simonw wrote Datasette[1] which makes extensive use of SQLite and acts as a viewer, allowing you to create interactive websites and APIs from arbitrary databases. He'd be a very long term plant and it instead seems far more likely he's interested in the possibilities of DuckDB compatibility within the context of Datasette and other similar projects.

[1]: https://github.com/simonw/datasette

Re:DuckDB – An embeddable SQL database like SQLite, but supp... by simonw on Sunday September 20, 2020 @12:36AM (#24531917)
I actually started looking at it today because someone was asking about it on the Datasette discussions board: https://github.com/simonw/datasette/discussions/968
Re:DuckDB – An embeddable SQL database like SQLite, but supp... by gregsadetsky on Sunday September 20, 2020 @12:22AM (#24531879)
I don’t think that it’s reasonable to assume that Simon would risk his reputation by coming here to astroturf.