$ show Evokoa/pgGraph
pgGraph is a PostgreSQL extension written in Rust (via pgrx) that adds high-performance graph query capabilities directly into PostgreSQL. It allows users to model graphs by registering existing relational tables as nodes and edges, building a compressed sparse row (CSR) adjacency index for sub-millisecond traversals, shortest paths, and connected components. The extension exposes SQL functions (`graph.traverse`, `graph.shortest_path`, `graph.search`, `graph.gql`, `graph.cypher`) and supports both openCypher and a subset of GQL for querying property graphs. It integrates deeply with PostgreSQL security (row-level security, multi-tenancy, ACLs), provides resource governance (memory, disk, work unit budgets), and includes a durable projection layer with atomic manifests, delta segments, compaction, and crash recovery. The codebase is structured as a pgrx extension with a Rust core, SQL bootstrap scripts, background workers for build/maintenance jobs, and an extensive test suite including fuzz targets, property-based tests, and heavy integration tests for concurrency, crash recovery, and performance gates.
The LLM identified 3 files worth highlighting for reuse:
Provides a thin abstraction over memory-mapped files (Mmap) and owned byte vectors (Vec<u8>), enabling production use of mmap-backed data and test use of owned byte arrays without code duplication. The type supports Arc sharing and is used as the backing store for all on-disk graph artifacts. It is a self-contained, highly reusable pattern for any Rust project that needs to switch between mmap and owned memory.
Implements a ResourceGovernor with typed budgets for memory, disk, rows, work units, and elapsed time, along with ResourceLease and DiskLease RAII wrappers. It enforces quotas via try_reserve and check_postgres_interrupts, and supports adaptive batch flushing. Though coupled to PostgreSQL error handling, the core pattern of resource accounting with phases and leases is architecturally clean and could be extracted as a standalone Rust crate for resource-constrained execution.
Manages a cumulative, CRC32-checksummed mapping from edge type IDs to logical labels (OIDs). Supports append-only growth with atomic publication via manifest, and is read via mmap. The design ensures that all historical mappings remain valid and that dictionary files can be validated on load. This pattern is reusable for any system needing a durable, append-only, checksummed dictionary for enumerated types.