CSR and algorithms
DuckDB tables remain authoritative. DuckGQL builds an explicit, connection-local CSR snapshot when you want graph algorithms or selective adjacency access.
Build the snapshot
CALL gql_build_csr('social');CSR construction must run in autocommit mode.
Run algorithms
CALL algo.bfs('social', 1, direction := 'out', max_depth := 4);CALL algo.pagerank(
'social',
damping := 0.85,
max_iterations := 100,
tolerance := 1e-8
)
YIELD vertex_id, rank
RETURN vertex_id, rank
ORDER BY rank DESC
LIMIT 10;Implemented algorithm families include BFS, DFS, unweighted SSSP, PageRank, weak and strong components, degree, closeness, local clustering coefficient, and triangle counting. Weighted SSSP is not implemented.
Algorithm output can yield properties from the participating vertices directly. For example, if the social graph has a name property:
CALL algo.degree('social')
YIELD name, out_degree, in_degree, total_degree
RETURN name, out_degree, in_degree, total_degree
ORDER BY total_degree DESC, name ASC
LIMIT 10;Inspect adjacency and statistics
CALL gql_neighbors('social', 1, 'out');
SELECT * FROM gql_csr_stats('social');
SELECT * FROM gql_csr_edge_stats('social');Edge statistics include per-type counts, active source and target counts, average directional degree, and maximum directional degree. The optimizer uses them to compare a selective CSR frontier with a bulk edge-table scan.
Snapshot invalidation
Graph mutations and direct SQL writes to managed graph tables invalidate the affected snapshot. Rebuild it before the next algorithm call:
CALL gql_build_csr('social');DuckGQL version-checks snapshots rather than allowing an algorithm to consume stale topology.