Menu

Post image 1
Post image 2
1 / 2
0

Your PostgreSQL Already Has a Graph Engine — You Just Have to Build It

DEV Community·Eugene·26 days ago
#ZEpuhjfr
Reading 0:00
15s threshold

We Replaced Recursive CTEs with a C Traversal Framework and Got ×207 Faster TL;DR: We built pg_igraph — a graph engine inside PostgreSQL as a C extension. The first working version used recursive CTEs. It took 47 seconds to traverse a 335K-node tree. The final version uses an in-memory adjacency list with pure-C BFS. The same query takes 227ms. Here's why CTEs are the wrong tool for this, and what the right tool looks like. The Setup We had graph-shaped data — users, relationships, hierarchies — and it lived in PostgreSQL. The standard answer is "use Neo4j," but that means a second database to deploy, back up, and keep in sync. For a graph that fits on one server, that felt like unnecessary complexity. So we built pg_igraph : a PostgreSQL C extension with BFS traversal, bidirectional shortest path, and a small query language.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More