Property Graph, Walk & Cypher
Graph adjacency indexes, 10 native graph pipeline algorithms, SQL graph TVFs, and Cypher / GQL MATCH pattern queries.
In SpydDB, the graph is your transactional rows. There is no separate eventual-consistency graph store to ETL into or keep synchronized: any collection containing node identifiers (u64, i64, uuid, or string/text) supports graph traversals, 10 built-in graph algorithms, SQL graph Table-Valued Functions, and Cypher / GQL MATCH queries—all governed by full MVCC snapshots, row-level policies, and multi-tenant isolation.
1. Adjacency Graph Index (USING graph)#
While graph operations work on any edge collection automatically, adding a USING graph index pre-indexes adjacency lists so multi-hop traversals only touch neighbors of visited nodes instead of scanning the entire edge table:
create collection transfers {
id: u64 primary,
from_id: u64,
to_id: u64,
cost: f64,
kind: text
};
-- Optional adjacency index over source -> destination node columns
create index idx_transfers_graph on transfers (from_id, to_id) using graph;- Derived indexes track collection write epochs and rebuild transparently whenever committed writes invalidate stale adjacency state.
- Run
explain analyzeon awalkorshortest_pathpipeline to verify index usage (shortest_path (graph index)).
2. Native SpydQL Graph Traversals & 10 Algorithms#
Pipe any filtered edge relation into walk or one of SpydDB's graph analytics stages using over <from_field>, <to_field>:
Multi-Hop Traversal (walk)#
-- Explore all vertices reachable within 2 hops starting from filtered seed edges
transfers
| where from_id == 1
| walk 2 over from_id, to_id
| sort node;
-- Emits columns: (node, hops)Weighted Shortest Path (shortest_path)#
Uses Dijkstra when weight <field> is supplied (failing closed if any negative edge weight is encountered):
-- Directed weighted shortest path from node 10 to node 40
transfers
| shortest_path from 10 to 40 over from_id, to_id weight cost;
-- Emits columns: (start, target, path, cost, hops)Complete Graph Algorithm Operators#
| Operator | Syntax | Output Columns | Notes |
|---|---|---|---|
| BFS / Reachability Walk | walk <hops> [weight <w>] over <from>, <to> | node, hops | Capped at MAX_HOPS = 16, MAX_VISITED = 100,000 (configurable via engine limits) |
| Shortest Path | shortest_path [from <s>] to <t> [max_hops <n>] [weight <w>] over <from>, <to> | start, target, path, cost, hops | Directed/weighted Dijkstra |
| Node Degree | graph_degree [for <node>] over <from>, <to> | node, in_degree, out_degree, degree | Computes in/out/total degree for one node or all vertices |
| PageRank | pagerank [damping <d>] [tolerance <t>] [iterations <n>] over <from>, <to> | node, rank | Iterative power iteration (capped at 1,000 passes) |
| Connected Components | components over <from>, <to> | node, component | Weakly connected component IDs |
| Strongly Connected Components | strongly_connected_components over <from>, <to> | node, component | Directed cycle/SCC decomposition |
| Community Detection | graph_communities [iterations <n>] over <from>, <to> | node, community | Label propagation (capped at 100 passes) |
| Betweenness Centrality | graph_betweenness [normalized true|false] over <from>, <to> | node, score | Brandes shortest-path centrality |
| Closeness Centrality | graph_closeness over <from>, <to> | node, score | Reciprocal farness score |
| Triangle Count | graph_triangles over <from>, <to> | node, triangles | Undirected 3-cycle count per vertex |
Example analytical pipeline combining PageRank and top-k filtering:
transfers
| pagerank damping 0.85 iterations 30 over from_id, to_id
| sort rank desc
| take 10;3. SQL Graph Table-Valued Functions#
Every core graph capability is also exposed as a PostgreSQL-compatible table function for pgwire clients and BI tools:
-- Breadth-first traversal up to 2 outbound hops from node 1
SELECT node, hops
FROM graph_walk('transfers', 1, 2, 'out', 'from_id', 'dst')
ORDER BY node;
-- Shortest path between two nodes (max 10 hops)
SELECT start, target, cost, hops
FROM graph_shortest_path('transfers', 1, 5, 10, 'out');
-- Degree centrality for node 3
SELECT node, in_degree, out_degree, degree
FROM graph_degree('transfers')
WHERE node = 3;
-- PageRank (damping = 0.85)
SELECT node, rank
FROM graph_pagerank('transfers', 0.85)
ORDER BY rank DESC;
-- Weakly & strongly connected components
SELECT node, component FROM graph_components('transfers');
SELECT node, component FROM graph_scc('transfers');Direction arguments accept 'out', 'in', or 'both'.
4. Cypher / GQL MATCH Pattern Queries#
SpydDB includes a native Cypher / ISO GQL MATCH engine directly on top of relational/document collections:
-- Directed single-hop and multi-hop variable-length pattern match
MATCH p = (a:Account {tier: "vip"})-[e:TRANSFERRED*1..3]->(b:Account)
WHERE b.risk_score >= 0.80 AND a.region = "us-east"
RETURN DISTINCT a.id, b.id AS target_id, length(p) AS path_len, b.risk_score
ORDER BY path_len ASC, b.risk_score DESC
SKIP 0
LIMIT 25;Supported Cypher / GQL Grammar#
- Node & edge bindings:
(a:Label {prop: val}), undirected--/-[]-, incoming<-[e:Type]-, outgoing-[e:Type]-> - Variable-length paths:
*min..max(for example*1..4,*2..,*..3) - Path & graph functions:
length(p),hops(e),nodes(p) - String & scalar helpers in
WHERE/RETURN:contains,starts_with,ends_with,lower,upper,abs,coalesce, pluscount,sum,min,max,avg - Modifiers:
RETURN [DISTINCT],ORDER BY ... [ASC|DESC],SKIP/OFFSET,LIMIT - Query plan inspection: Prefix any Cypher query with
EXPLAIN MATCH ...to inspect the execution plan before running it.
5. Multi-Tenancy, RLS & Safety Limits#
- Zero policy bypass: Because graph scans and
MATCHbind through regular collection scans, tenant separation andCREATE POLICYrow filters automatically apply to vertices and edges alike. - Deterministic safety bounds: Default traversal limits (
MAX_HOPS = 16,MAX_VISITED = 100,000,MAX_PAGERANK_ITERATIONS = 1,000,MAX_COMMUNITY_PASSES = 100) prevent infinite cyclic traversals from exhausting query memory or worker threads.