LadybugDB v0.22.1

comparisons / duckdb & duckpgq vs ladybugdb

What is DuckDB for graphs?

Search for “DuckDB for graphs” and DuckDB’s own documentation answers first: DuckDB supports graph queries. On paper, that sounds like the end of the search. In practice, running real graph workloads on DuckDB and DuckPGQ exposes two hard realities — one about transactional correctness, and one about what happens when graph traversals stop looking like flat SQL joins.

The promise — and what DuckDB actually runs

DuckDB earned its reputation the hard way. It proved that an embedded, single-file, MIT-licensed columnar engine with vectorized execution could chew through analytical queries on a laptop faster than clusters that cost ten times as much to run. So when teams start working with connected data — social networks, fraud rings, knowledge graphs, agent memory — the first question they type into a search bar is completely natural: what is DuckDB for graphs?

Right near the top of the results sits duckdb.org:

“DuckDB supports graph queries. Graph queries allow you to find patterns and paths in connected data, such as social networks, financial transactions, or knowledge graphs, using a visual, intuitive syntax.”

DuckDB documentation, via the DuckPGQ community extension

It is an appealing pitch. Install a community extension (INSTALL duckpgq FROM community), declare a SQL:2023 property graph view over your regular DuckDB tables, and write GRAPH_TABLE (... MATCH ...) right inside SQL. No second database, no new file format, no migration.

The catch is how DuckPGQ executes what you write. Under the hood, every graph query splits down one of two completely different paths. Fixed-length MATCH patterns are rewritten by PGQMatchFunction::MatchBindReplace into ordinary DuckDB SQL joins — they inherit DuckDB’s relational optimizer and MVCC snapshot isolation because they are just SQL joins. Everything else — variable-length traversals, ANY SHORTEST, reachability, weakly connected components, PageRank, clustering — cannot be lowered into flat joins. For every one of those queries, DuckPGQ scans your tables to construct an ephemeral in-memory Compressed Sparse Row (CSR) structure on the fly, runs path traversal against it, and throws the CSR away when the query finishes.

DUCKDB + DUCKPGQ · EXTENSION OVER RELATIONAL TABLES DuckDB tables MVCC · raw storage rowid Fixed-length MATCH rewritten to SQL joins Snapshot-safe flat relational execution Paths & graph algos ephemeral CSR · raw rowid · id=0 Breaks on mutations segfaults & rowid-hole crashes LADYBUGDB · NATIVE COLUMNAR GRAPH ENGINE Columnar + persistent CSR native adjacency · logical IDs Factorized Cypher engine vectorized · ACID · WCOJ Full graph workloads paths, NaviX, Icebug, DuckDB
DuckPGQ lowers fixed patterns to SQL joins and builds an ephemeral raw-rowid CSR for paths; LadybugDB stores and queries persistent columnar CSR natively.

A quick CSR primer: dense rowids, bitmasks, and on-disk storage

To understand both why DuckPGQ breaks under mutations and why a native graph engine pulls 15×–44× ahead on heavy multi-hop joins, it helps to look at Compressed Sparse Row (CSR) — the core data structure behind fast graph traversal. Instead of scattering edges across a flat join table and probing a hash table on every hop, CSR packs all edges into two contiguous arrays: an offsets array indexed by dense vertex ID 0..N-1, and a flat neighbors array (with aligned edge-property columns). Reading every neighbor of vertex v is an O(1) slice — neighbors[offsets[v] .. offsets[v+1]] — streamed sequentially through CPU cache lines.

ADJACENCY MATRIX (4×4) 0 1 2 3 v0 · 1 1 · v1 · · 1 1 v2 · · · 1 v3 · · · · sparse: 5 edges in 16 slots CSR COMPRESSED SPARSE ROW (CONTIGUOUS ARRAYS) offsets len N + 1 0 1 2 3 4 0 2 4 5 5 neighbors len E = 5 1 2 2 3 3 0 1 2 3 4 edge_props e.g. since 2021 2022 2020 2024 2023
Compressed Sparse Row (CSR): offsets[v]..offsets[v+1] slices vertex v’s contiguous neighbors and aligned edge properties in O(1) without storing empty cells.

That dense 0..N-1 rowid space is also what makes bitmask-based join processing so effective. When every vertex occupies a compact integer offset, any filtered subset of vertices — say, every Person matching a predicate or every node reached at hop two — collapses into a dense bitmask: one bit per vertex, so a million vertices fits in 125 KB of L2 cache. During multi-hop joins and sideways information passing (SIP), checking whether a candidate neighbor qualifies becomes a single bit test (mask[v >> 6] & (1ULL << (v & 63))) instead of hashing keys and probing a multi-megabyte hash table. The same dense offset space turns BFS visited sets and graph-algorithm frontiers into flat bitsets.

DENSE ROWIDS ENABLE O(1) BITMASK JOIN FILTERING 1. CSR slice (v1) idx 2 idx 3 2 3 neighbors[offsets[1]..offsets[2]] test 2. Dense bitmask (0..3) v0 v1 v2 v3 0 1 0 1 1 bit / vertex · 1M nodes = 125 KB keep 3. Surviving match 3 bit test only · no hash probe
Because vertex IDs are dense in 0..N-1, semi-join filters and SIP masks fit in CPU cache and prune neighbors (v2 dropped, v3 kept) with a single bit test.

The architectural divide is where that CSR lives. LadybugDB maintains dedicated on-disk CSR data structures partitioned into node groups — compressed offset headers, neighbor lists, and edge-property columns managed through its buffer manager, with updates and deletes tracked cleanly inside node-group storage (and readable directly from Parquet/S3 via icebug-format). Graphs persist in CSR form, scale larger than RAM, and are ready to traverse immediately with zero rebuild tax. DuckDB has no on-disk CSR format: DuckPGQ builds its CSR strictly in memory via full table scans on every path query and discards it when the query ends. Worse, because DuckPGQ tried to get dense offsets for free by indexing its in-memory CSR directly with DuckDB’s raw storage rowid, transactional mutations break it immediately.

First, correctness: what happens when the graph changes

Before looking at millisecond timings, a database has to survive ordinary SQL transactions. We ran standard MVCC probes — own-write visibility, rollback atomicity, delete visibility, and repeat-query consistency — against DuckPGQ on a three-node graph (Person(1..3), Knows(1→2, 2→3)), comparing every PGQ query against plain SQL in the same transaction.

Fixed-length MATCH passed every probe, because DuckPGQ simply rewrites it into DuckDB joins. But every query that touched DuckPGQ’s ephemeral CSR — variable-length paths, ANY SHORTEST, reachability, and graph algorithms — failed under ordinary mutations. The root cause is architectural: CreateCsrVertexFunction indexes C arrays directly with DuckDB’s raw storage rowid (csr->v[src+2] = cnt) with no bounds checking, assuming rowid is always dense in [0, count). DuckDB’s MVCC storage never promises that invariant.

Uncommitted rows inside a transaction receive temporary rowids around 2^55 (36028797018960000). Insert a vertex inside BEGIN and run a shortest-path query — the most basic “create node, traverse from it” application pattern — and the unchecked array write immediately kills the database process with a segmentation fault.

Deleting a vertex is even worse because it requires no open transaction at all. A committed DELETE FROM Person WHERE id = 2 leaves rowids {0, 2} with count = 2. Every subsequent path query allocates a vector of size 2, indexes position 2, throws INTERNAL Error: Attempted to access index 2 within vector of size 2, and fatally invalidates the database handle, forcing a restart. Running VACUUM Person does not compact rowids — the table remains permanently broken for path queries until you rebuild it from scratch.

-- 1. Transactional INSERT + path query → process segfault
BEGIN;
INSERT INTO Person VALUES (4, 'Dave');  -- txn-local rowid ≈ 2^55
SELECT count(*) FROM GRAPH_TABLE (
    pg MATCH p = ANY SHORTEST (a:Person)-[k:Knows]->{1,3}(b:Person)
    COLUMNS (a.name AS an, b.name AS bn)
);
-- Result: Segmentation fault in CreateCsrVertexFunction (process dead)

-- 2. Committed DELETE + path query → permanent crash & DB invalidation
DELETE FROM Person WHERE id = 2;       -- leaves rowid hole {0, 2}, count = 2
DELETE FROM Knows  WHERE src = 1;
SELECT count(*) FROM GRAPH_TABLE (
    pg MATCH p = ANY SHORTEST (a:Person)-[k:Knows]->{1,3}(b:Person)
    COLUMNS (a.name AS an, b.name AS bn)
);
-- Result: INTERNAL Error: Attempted to access index 2 within vector of size 2
-- Result: FATAL: database invalidated, must restart (VACUUM does not fix)

Two more defects surface even without deleting vertices. Every generated CSR fragment hardcodes CSR ID 0 (create_csr_vertex(0, …)), so combining two path queries in one statement with UNION ALL double-appends edges into the same fixed-size vector and throws an internal error — even on read-only, committed, hole-free tables. And an uncommitted edge-only insert avoids the segfault (vertex rowids remain dense) only to leak the transient storage rowid ([0, 36028797018960000, 2]) straight to the client via element_id(p).

Transactional probe DuckPGQ LadybugDB
Insert + path query in one txn Process segfault in CreateCsrVertexFunction Snapshot-correct results
Delete a vertex, keep querying Permanent crash + DB handle invalidated Correct immediately
UNION ALL two path queries Internal error (hardcoded CSR id 0) Correct
Element identity on uncommitted edge Leaks transient storage rowid (≈ 2^55) Stable logical IDs
Fixed-length MATCH lookups Correct (rewritten to SQL joins) Correct

Until DuckPGQ keys its CSR by snapshot-computed dense IDs instead of raw rowid, bounds-checks CSR writes, and allocates distinct CSR IDs per CTE, fixed-length matching is the only part of the extension honoring the transactional contract — and you do not need a graph extension to run SQL joins.

What about raw query speed? Three workloads compared

Set mutations aside and look at read-only performance. Even on clean, static graphs, the answer to “how well does DuckDB run graph queries?” depends sharply on what shape of graph query you actually run. Looking at three distinct workloads side by side makes the boundary unmistakable.

1. Count-only subgraph patterns (LSQB)

The Labelled Subgraph Query Benchmark (LSQB) is an unofficial benchmark widely used to compare count-only fixed-length graph patterns. It is worth showing all nine queries transparently, because the split between DuckDB 2.0.1 and Ladybug 0.23.1 tells you almost everything about relational versus graph execution.

Query Count DuckDB 2.0.1 (s) Ladybug 0.23.1 (s) Faster Speedup
1 45,515,831 0.0938 0.1906 DuckDB 2.03×
2 277,454 0.0191 0.1379 DuckDB 7.22×
3 140,736 0.0267 0.7340 DuckDB 27.49×
4 3,461,431 0.0640 0.3065 DuckDB 4.79×
5 3,703,494 0.0725 0.1008 DuckDB 1.39×
6 285,509,755 0.9933 0.0663 Ladybug 14.98×
7 6,456,925 0.0856 0.5372 DuckDB 6.28×
8 1,848,731 0.0834 0.2042 DuckDB 2.45×
9 268,837,983 1.0166 0.0231 Ladybug 44.01×

Credit where it is due: on seven of the nine count-only patterns — flat relational joins and star schemas with modest fanout — DuckDB 2.0.1 is genuinely faster. That is what DuckDB’s hash-join engine was built to dominate. Then look at Queries 6 and 9, the two queries where the graph stops looking like a flat star join and explodes into 269–285 million friend-of-a-friend combinations (KNOWS–KNOWS–HAS_INTEREST, plus the NOT KNOWS anti-join in Query 9). Flat binary joins have to materialize that intermediate blowup; LadybugDB’s persistent CSR adjacency lists and factorized execution keep repeating bindings compressed, finishing 15× faster on Query 6 and 44× faster on Query 9.

2. 30 simple multi-hop queries over LDBC SNB SF1 (graph-benchmark-ldbc)

Count-only queries rarely look like production applications, which filter, traverse multiple hops, and project node and edge attributes. In HDC Labs’ 30-query benchmark over the LDBC SNB SF1 graph (3.18M nodes, 17.26M relationships; independent and unaudited, not official LDBC Benchmark Results), both Ladybug 0.23.0 and DuckPGQ on DuckDB 1.5.6 were tested on the same Apple M5 machine with six matching ART secondary indexes.

It is worth being clear about what this suite actually measures: most of the 30 queries are simple, selective, fixed-length lookups that finish in a millisecond or two. That is why the headline winner across many of those tiny queries is FalkorDB, a RedisGraph-derived in-memory database that relies on index nested-loop joins (INLJ) for every query — when queries are simple, the engine with the simplest structure and lowest per-query overhead wins. The tradeoff shows up immediately on q30, the one heavy join in the suite, where FalkorDB’s planner pairs ~447M candidates and times out past 10 seconds (61.9 s uncapped).

Because all 30 queries are fixed-length MATCH patterns, DuckPGQ stays entirely on its safe SQL-join fast path and never touches its broken CSR path. Even on that favorable slice, Ladybug 0.23.0 is faster than DuckPGQ 1.5.6 on 22 of the 30 queries, delivering a 1.65× geometric-mean speedup across the suite (and up to 5.2× faster on selective traversals). DuckPGQ wins 8 of the 30 queries, led by scan-heavy patterns like q7, q5, and q30.

Slice (30-query SF1 suite) Ladybug 0.23.0 (ms) DuckPGQ 1.5.6 (ms) Ratio
q2 · creator + content filter 0.664 3.450 Ladybug 5.20×
q4 · multi-hop traversal 0.346 1.545 Ladybug 4.47×
q16 · filtered path 0.773 3.400 Ladybug 4.40×
q22 · multi-hop join 1.555 5.143 Ladybug 3.31×
q7 · best DuckPGQ win 6.508 2.666 DuckPGQ 2.44×
q30 · largest join in suite 42.825 26.809 DuckPGQ 1.60×
All 30 queries (Ladybug faster on 22 / 30) 79.24 total 84.35 total 1.65× geomean

3. Complex interactive graph queries (graph-benchmark-ldbc-complex)

The third workload is where graph databases actually earn their keep. HDC Labs’ complex suite adapts all 14 LDBC SNB Interactive complex read queries (IC1–IC14) over SF1 (again independent and unaudited, not official LDBC results). These queries combine bounded shortest-path search (shortestPath((p)-[:knows*1..3]-(friend)) in IC1), enumerating allShortestPaths and scoring every hop by bidirectional post and comment replies (IC14), chained OPTIONAL MATCH clauses, nested collect() aggregations, and multi-hop ranking.

Notice who is missing from the benchmark: DuckPGQ is not in the suite at all. Only Neo4j, Kuzu, LadybugDB, and lance-csr run all 14 complex queries against the golden answers. Ladybug 0.22.1 passes every golden-answer check, posts the lowest mean latency of any tested engine on 6 of the 14 queries (IC4, IC6, IC8, IC10, IC11, IC14), and runs up to 24× faster than Neo4j — while Neo4j still wins tightly point-seeded IC7 and IC13.

Query Neo4j 2026.09.0 (ms) Kuzu 0.11.3 (ms) Ladybug 0.22.1 (ms) Ladybug vs Neo4j
IC151.413.536.81.40×
IC244.725.06.17.34×
IC3894.9105.2116.37.69×
IC413.129.75.62.34×
IC51,022.6747.7263.03.89×
IC6231.21,114.89.623.97×
IC77.1453.7304.70.02×
IC83.073.40.93.44×
IC9802.3131.057.114.05×
IC1091.774.911.57.94×
IC1111.04.71.76.53×
IC12133.992.322.85.88×
IC130.914.248.50.02×
IC14522.61,871.288.05.94×

Join algorithms: what DuckDB adopted — and where the gaps remain

It is worth being fair about how fast DuckDB itself has evolved. DuckDB has implemented sideways information passing (SIP), worst-case optimal join (WCOJ) techniques, and several other execution ideas described in the Kuzu VLDB/CIDR paper. Those improvements are a major reason DuckDB 2.0.1 is so strong on flat count-only joins like LSQB Queries 1–5, 7, and 8.

Yet clear gaps remain — both on explosive many-to-many joins (15× on LSQB Query 6, 44× on Query 9) and on complex interactive graph workloads (IC1–IC14) — for two structural reasons:

First, focus on graphs. DuckDB’s optimizer, physical operators, and engineering roadmap are centered on general-purpose relational SQL over flat tables. In LadybugDB, graph execution is the primary workload: factorized tuple representations that keep list-valued neighbor bindings compressed instead of materializing 285-million-row Cartesian intermediates, ASP and WCOJ join plans wired directly into Cypher pattern planning, native bidirectional shortest-path and recursive join operators, and cardinality estimation built for skewed degree distributions.

Second, CSR on disk. Join algorithms do not run in isolation — they sit on top of a storage layout. Because LadybugDB persists CSR adjacency lists on disk with dense node-group offsets, join operators can scan contiguous neighbor slices directly, apply dense bitmask semi-join filters in cache, and evaluate multi-way intersections and anti-joins (like NOT KNOWS in LSQB Query 9) without scanning flat edge tables to build hash tables or reconstruct an in-memory CSR on every query. Without on-disk CSR, even strong relational join algorithms still pay the cost of flat tabular storage underneath.

What “DuckDB for graphs” actually means

None of this is an argument against DuckDB. DuckDB is extraordinary at relational analytics, and if your graph queries are really just two- or three-table star joins over static tables, plain DuckDB SQL will fly. What the correctness probes and benchmarks show is simpler: bolting graph syntax onto a relational engine through an ephemeral, per-query CSR is not the same thing as building a DuckDB-class engine for graphs.

What made DuckDB transformative for tables was never syntax alone. It was designing the storage layout, execution engine, and packaging around the workload from day one — compressed columns, vectorized operators, zero-dependency embedding, and an MIT license. LadybugDB (carrying forward KuzuDB’s CIDR/VLDB 2023 and VLDB 2025 research lineage) applies that exact philosophy natively to property graphs: persistent columnar CSR adjacency lists, factorized execution that survives 285-million-row many-to-many traversals, ACID transactions that don’t crash when you insert or delete a vertex, portable Cypher, peer-reviewed NaviX filtered vector search, and more than 220 zero-copy graph algorithms in Icebug.

Best of all, you do not have to choose one and throw away the other. LadybugDB ships a built-in DuckDB extension that attaches your DuckDB files directly, alongside Parquet, Arrow, Iceberg, Delta, Postgres, and icebug-format on object storage. Let DuckDB do relational analytics on your tables, and let LadybugDB run the graph.