14 ms·
DuckDB: SQLite for Analytics
- banana_giraffe 7y agoAs someone that uses SQLite a bit for analytics, I feel like the elevator pitch on the github and the website ( https://www.duckdb.org/ https://www.duckdb.org/ ) is missing something. I'm sure there's some great reason, but I don't see it: Why would I want to use this over SQLite? Is it considerably faster? Does it handle large scale better? I suppose I could try and throw it some use cases I could come up with, but I'd worry I'm missing the best use case for this tool.
- cheez 7y agoSame. Best elevator pitch would be how it complements (or replaces) SQLite
- tdeck 7y agoJust came here to say the same thing. I read the readme and it's not clear what this does exactly as compared to SQLite, particularly since it used SQL. What kinds of analytics is it optimized for? Does it have different data structures for streaming data? I can tell a lot of work went into this project and I think it could benefit from a more thorough introduction.
- jabba_d_hut 7y agoIt's a columnar database and the query engine is inspired from MonetDB which processes columns in vectors - "Execution engine: The vectorized execution engine is inspired by the paper "MonetDB/X100: Hyper-Pipelining Query Execution" by Peter Boncz, Marcin Zukowski and Niels Nes.".
- tdeck 7y agoInteresting that the distinctive features are buried in the acknowledgements section.
- pgwhalen 7y agoI wouldn't call that "buried in the acknowledgements section." I wish more software projects would present themselves in this way actually. Inevitably everything is built upon prior art, so it makes sense to say where the ideas came from or which parts are novel (if any - sometimes packaging together a bunch of existing ideas is valuable in itself). It sure beats "[project] is a new key-value store that is even faster than [other project]".
- mkl 7y agoAgreed. I was trying to understand it earlier, and there doesn't seem to be a description of what its features are and what it's good for. It jumps straight to "how to use" without "why to use".
- ngenstyle 7y agoMy first instinct based on a cursory glance (ie. specific language compatibilities) is that it's a portable embedded database for data analytics of the cybersecurity domain, particularly mobile penetration testing possibly.
- jdotjdot 7y agoAdding to the pile of people agreeing. SQLite works okay for analytics for now, and I would be super-interested in something embeddable more tailor-made for analytics, but don't understand yet in what specific ways DuckDB is an improvement.
- kyllo 7y agoHere's a YT video of one of the implementers giving a talk to CMU students about what DuckDB is, why they made it, and how it works: https://www.youtube.com/watch?v=PFUZlNQIndo https://www.youtube.com/watch?v=PFUZlNQIndo In a nutshell, it's a file-per-database embedded DB like SQLite, and it's installable as a Python or R package from PyPI or CRAN, but unlike SQLite, it's a column store with vectorized operations so it's more performant for analytical queries.
- alecco 7y agoI usually just extend SQLite with virtual columns and try to do the filtering/aggregate before sending tuples to the engine. This does the trick most of the time and it's relatively straightforward to implement.
- mywacaday 7y agoI'm need to move an excel sheet to something like SQLite, hadn't heard of virtual columns, fixes most of the issues I have, thanks!
- stingraycharles 7y agoThe fact that it’s column oriented is a massive improvement for analytics over SQLite, I don’t understand why they don’t mention this more explicitly on their website and GitHub pages.
- sradman 7y agoThe video clarified my initial confusion. DuckDB is an embedded column store library and borrows the SQLite C API and some of the SQLite philosophy (single cpp/hpp amalgamation file, no external dependencies, and resource sharing) but it uses PostgreSQL syntax and parser, and a column oriented memory/storage engine based on their experience with MonetDB/VectorWise. DuckDB borrows code from HyPer DB which looks like a in-memory hybrid OLTP/OLAP clone of SAP HANA. They did not discuss any hybrid OLTP/OLAP implementation details in the video so the borrowed HyPer code may only be the wrapper for the PostgreSQL parser. Desktop column stores do have a precedent in the enterprise market. Microsoft's first attempt at a column store started with embedded integration with PowerPivot and eventually made its way into SQL Server. Sybase IQ, built on zero-admin SQL Anywhere, has been used as a local column store for Pivot Table applications (think BusinessObjects, Cognos, Tableau, QlikView, and Excel Pivot Tables). Pivot Table integrations are typically custom-built for each data warehouse vendor or MDX/XMLA driver. DuckDB is focused on integrating with the desktop data science platforms R and Python (dbplyr and pandas). Analytics/OLAP in SQL means lightning fast GROUP BY queries and more recently SQL OLAP Windows. "SQLite for Analytics" confused me but that is probably due to my own historical mental clutter. The name DuckDB refers to a pet duck and not the duck typing system in SQLite.
- georgewfraser 7y agoIt’s much faster for analytical queries, because it’s a column store rather than a row store.
- ivan_ah 7y agoSome more info about columnar DBs here https://en.wikipedia.org/wiki/Column-oriented_DBMS https://en.wikipedia.org/wiki/Column-oriented_DBMS for anyone not familiar with the idea.
- wenc 7y agoI bookmarked DuckDB some time ago intending to revisit, and when I did, I had forgotten why I bookmarked it and the website's contents unfortunately didn't help for reminding me. If the documentation had said something like "a columnar database based on sqlite, optimized for analytics", I think that would pique the interest of many. Columnar database = column compression = fast filtering/aggregations = high performance analytics compared to pure row stores. There are very few free columnar databases available that are production grade (or built on production grade technology), so a columnar database built on top of sqlite is big news.
- mytherin 7y agoApologies, a website rework is currently in progress :) DuckDB is indeed a free columnar database system, but it is not entirely built on top of SQLite. It exposes the same front-end and uses components of SQLite (the shell and testing infrastructure), but the execution engine/storage code is new.
- erichocean 7y agoI can see why you are avoiding "built on top of SQLite", but I really think you should reconsider and go with that terminology. It means the "right" thing to most people: I can use this like I use SQLite now.
- smbrian 7y agoThe pitch is faster, and more space efficient since column stores are far better for analytics than row stores. Some benchmarks that found ~5-10x speedup: https://uwekorn.com/2019/10/19/taking-duckdb-for-a-spin.html https://uwekorn.com/2019/10/19/taking-duckdb-for-a-spin.html Consider someone who analyzes medium-sized volumes of (slowly-changing) data -- OLAP, not OLTP. People who need to do this primarily have 2 alternatives: * columnar database (redshift, snowflake, bigquery) * a data lake architecture (spark, presto, hive) The latter can be slow and wasteful, because the data is stored in a form that allows very limited indexing. So imagine you want query speeds that require the former. Traditional databases can be hugely wasteful for this usecase -- space overhead due to no compression, slow inserts due to transactions. The best analytics databases are closed-source and come with vendor lockin (there are very few good open-source column stores -- clickhouse is one, duckdb is another). Most solutions are multi-node, so they come with operational complexity. So DuckDB could fill a niche here -- data that's big enough to be unwieldy, but not big enough to need something like redshift. It's analogous to the niche SQLite fills in the transactional database world.
- cheez 7y agoI read the post and had a couple of points: 1. Is DuckDB similar to having indexes on each column? Because generally when something is slow, the solution is indexes. I have a 100 GB database which records real time data and is lightning fast because of some minor tuning. 2. The example of STDDEV not be available shows the author's unfamiliarity with SQLite which worries me. https://docs.python.org/2.7/library/sqlite3.html#sqlite3.Connection.create_function https://docs.python.org/2.7/library/sqlite3.html#sqlite3.Con... Could very easily have made a similar interface if necessary.
- kyllo 7y agoIndexes don't solve the same problem as columnar because with an index you still have to dereference a pointer, read the page (performing I/O if on-disk), and locate each tuple you want within the page--the tuples you need to aggregate from may be scattered across many pages, and you have to read the whole page into memory even if you only want one column. With a column store, the values of the same column are stored contiguously so if you're summing a column for example, you can read one or more pages that could consist entirely of values the column you need to sum, sequentially. It's much more efficient for aggregations due to cache locality--much fewer cache misses and I/O operations needed to summarize a column. The major trade-off is that updates and deletes are more expensive in a column store. But this is usually fine for OLAP workloads.
- tejtm 7y agoIt might be dating me, but seem like a larger version of the difference between C and FORTRAN arrays, C being relational like and FORTRAN being column store like. now get off my lawn :)
- wenc 7y agoWell, seems to me the difference between rowstores and columnstores might be a little more profound than just row and column major orders in C and FORTRAN. (Which I remember from back in the day) In columnstores, it’s not just the ordering that’s advantageous for analytics. It’s also the possibility of scanning only the columns required (to the exclusion of others), and the possibility of column compression using RLE compression, which speeds up search when there are many repeated elements (also compression makes searches cache efficient). This means if you workload only involves a few columns, and your primary operations are filter and aggregate — analytics workloads — then the performance gains are tremendous. On the other hand, if you want to optimize for row by row writes (OLTP), and if your workloads involve operations on many columns, then a rowstore is advantageous. Row and column major layouts are more about exploiting sequentiality, but in practice both C and FORTRAN can provide good linear algebra performance. But for analytics workloads on row vs columnstores, the difference in performance can be in the orders of magnitude. The fastest analytics databases in the world (Kdb, Vertica, Exasol, some of the newer GPU based databases) are almost all columnar.
- jameskraus 7y agoIf you want to dig into the differences more, I highly recommend the book Designing Data Intensive Applications. Analytics systems have different requirements from normal transaction processing systems, so it naturally follows that DuckDB could specialize to fill those requirements better than SQLite. Many people bring up row stores (SQLite) vs column stores, but there are many other interesting differences and optimizations to be made, so I can see how SQLite may be leaving some niche unfilled.
- stereosteve 7y agoCMU database group videos recently had the duckdb lead on https://youtu.be/PFUZlNQIndo https://youtu.be/PFUZlNQIndo
- sheeshkebab 7y agoThis presentation was awesome!
- anarchyrucks 7y agoThanks! Loved the presentation.
- snissn 7y agoCan this be made into a back end for sqlite? edit example like this: https://github.com/LMDB/sqlightning https://github.com/LMDB/sqlightning
- alexdoesh 7y agoSQLIte v4 supposed to be built on top of LMDB as I remember. For some reason the project was closed, they even have note about it on the official site somewhere.
- hyc_symas 7y agoSQLite v4 was supposed to have modular, pluggable backends, of which LMDB was only the first (of hopefully many). They were also working on their own from-scratch implementation of an LSM backend, which was also abandoned. As I recall, they decided that the mmap-related performance tricks they learned from working with LMDB could just be plugged into their own SQLite v3 Btree engine. (Indeed, recent SQLitev3 is a bit faster than when the SQLitev4 project began. But still doesn't match LMDB.)
- hyc_symas 7y agoJust fyi, another dev team has picked up the SQLightning code and brought it up to date: https://github.com/LumoSQL/LumoSQL https://github.com/LumoSQL/LumoSQL
- lowkey 7y agoI just installed this and looking at the dependencies it includes both numpy and pandas. Could anyone advise how these relate to DuckDB? i.e. Is a DuckDB accessible as a Pandas dataframe?
- dloss 7y agoYes, the Python bindings include functions to deal with Pandas dataframes. Look at the examples: https://github.com/cwida/duckdb/blob/master/examples/python/duckdb-python.py https://github.com/cwida/duckdb/blob/master/examples/python/...
- econcon 7y agoI've been using clickhouse with our 100gb click log data per day. It just works, before that we were using bigquery and bigquery was cheaper than our home brewed solution :( So now we use two together, only recent data that's available for fast querying for user dashboard is served from clickhouse cluster. And old data were customer is willing to be more tolerant to slow responses upto 2seconds is served by bigquery.
- scoresmoke 7y agoWhen I was developing my pet project for Web analytics (https://github.com/dustalov/ballcone https://github.com/dustalov/ballcone), I aimed at using an embedded columnar database for fast analytic queries with zero maintenance, so literally, I wanted ‘OLAP SQLite’. There are essentially two options, DuckDB and MonetDBLite, developed by the same research group. I tried both of them. DuckDB is a relatively new project and I generally enjoyed its design and code quality. However, I found that its current implementation of storage works better for dense data, which is not my case: https://github.com/cwida/duckdb/issues/632 https://github.com/cwida/duckdb/issues/632. I think it would be pretty cool to have data compression and more careful NULL handling needed for storing HTTP access logs. MonetDBLite seems to be more mature in terms of functionality, but it seems to be lagging significantly behind the non-embedded client-server version, MonetDB: https://github.com/monetdb/monetdb https://github.com/monetdb/monetdb. I experienced unexpected segfaults when using the DATE type on any platform and window functions on aarch64. Nevertheless, I am still using MonetDBLite primarily due to the more efficient disk usage. I will be happy to switch to a more lightweight and actively maintained solution.
- stilisstuk 7y agoCan someone point me to what OLAP is? I've read the wiki page, but don't get. All the databases I have worked with are multidimenaional.(i.e. complex erp systems with 100's of tabled joined together in various ways). Granted most of my analytical work is done in R, after performing queries. But I've never had the need for 'special sql'. Is this 'cubes' all over? I understand cubes as basically views precalculated to perform faster on mostly to charge more? But OK... If need to work on datasets bigger than e.g. 5 GB you begin to eat RAM fast. Is this the use case? Then why not simply say that?
- DenisM 7y agoGoing by example, let's say you're designing a sales system. OLTP workload is when you create/read one order at a time, or a short list of them. OLAP workload is when you want to aggregate sales numbers across all orders for a given broad criteria, without particular interest in any one order. For example sales by customer by month, or sales by region by date. The two cases benefit from different data structures and algorithms to achieve their goals. A system for OLTP may have a table of orders T0 (id, date-time, customer, $total, address, ship method, contact person, ...) where any one record can be fetched efficiently. However reading all of them will require a lot of disk IO. A system for OLAP can reduce this table to T1 (id, date-time, customer, $total) or even just T2 (date-time, customer, $total) which is good enough to answer most statistical queries and yet consuming less than half the disk bandwidth. Further yet, you likely do not care about individual order made on a given date by a customer, so you can add up all orders for a given day before storing the data: T3 (day, customer, $total-for-the-day-for-this-customer), or for the week: T4 (week, customer, $total-for-the-week-for-this-customer) or for the months: T5 (month, customer, $total-for-the-month-for-this-customer). Alternatively if you're a big boss you may not care about individual customers, but may care about regions, so the table you will want to see is T6 (week, region, $total-for-the-week-for-all-customers-in-region). These smaller tables will answer your questions several orders of magnitudes faster compared to T0. And no, they do not have to fit into the memory - to the contrary the entire purpose of the exercise is to make it work efficiently with disk. One could also chose to not compute e.g. T6 and derive it on the fly from T4, it's slower than having T6 pre-computed, but allows more flexibility in e.g. computing sales by ZIP code or by proximity to major bodies of water, etc.
- mmsimanga 7y agoI know this isn't a support forum but as someone who works analytics I tend to use the same SQL editor to connect to different databases. At the moment it is DBeaver[0]. Maybe I am missing it but I cannot see how to connect to DuckDB using a regular SQL editor. [0]https://dbeaver.io https://dbeaver.io
- sceadu 7y agoTry connecting to it as if it's sqlite? Not sure if they match any existing wire protocol but that would be my guess if they do.
- justinclift 7y agoSQLite is an in-process database, so it doesn't really have a wire format.
- tmzt 7y agoAs a possible hack, you could rename it the soname as sqlite and put it first in the library search path. It would have to implement the same abi though.
- hathym 7y agotried the online version [1] this simple request does not seem to work for me: SELECT * FROM lineitem where l_discount < 1 any reason why? [1] https://duckdbdemo.project.cwi.nl/select.html https://duckdbdemo.project.cwi.nl/select.html
- lumost 7y agoI was looking for this exact type of project to back some of my ML projects datasets. These datasets - Are less than 1 TB at maximum, and are typically less than 50GB - Written once and read many times - Require heavy and variable post-processing prior to training - Usually run on an ephemeral large instance which reads from s3, does it's thing, and then shuts down. This last task is incredibly slow in python, and limited on a standard sqllite/postgres DB to a single thread. Having access to an embeddable columnar sql engine could greatly simplify and accelerate this final transformation stage before training.
- nojito 7y agoInstead of using python for data transformation, just move over to data.table. https://h2oai.github.io/db-benchmark/ https://h2oai.github.io/db-benchmark/ Cut your time AND your costs.
- nocitrek 7y agoI would convert the datasets to .csv (.parquet if needed), rent EC2 instance and load it with pandas. In my opinion you should thrive to have dataset in memory if possible - you will benefit from great iteration speeds on tweaking of your model.