Database Systems

How DuckDB is USING KEY to Unlock Recursive Query Performance

Björn BambergDenis HirnTorsten Grust

Proceedings of the 2025 ACM SIGMOD International Conference on Management of Data (SIGMOD'25), June 22–27, 2025, Berlin, Germany. (to be published)

SQL’s recursive common table expressions (CTEs) can express complex computations over tabular data. Their accumulative semanticswhich collects all intermediate results in a union table—may incur substantial space and runtime overhead, however. This paper takes the recently proposed USING KEY variant of recursive CTEs as a starting point and demonstrates it as a production-ready feature in DuckDB. This CTE variant admits queries to selectively “overwrite” prior intermediate results, which ultimately leads to substantially smaller union tables and runtime savings. We present the changes we made to DuckDB to support this new CTE form and showcase the performance of the USING KEY variant using the LDBC graph instances. The demonstration features a fully functional implementation of USING KEY in a DuckDB instance, pre-loaded with LDBC graphs, and a large set of queries that demonstrate the benefits. The demonstration will be interactive, allowing attendees to play with sample SQL queries and data.