News for hackers. Stuff that matters.
Re:Postgres as a Graph Database: (Ab)Using PgRouting by nemo44x on Thursday February 27, 2025 @07:47PM (#43200346)
Neo4j is pretty bad and very dated. No idea what they’re doing. MemGraph is a much better tool.

Really graph is a feature and not a product.

Re:Postgres as a Graph Database: (Ab)Using PgRouting by threeseed on Thursday February 27, 2025 @11:46PM (#43201796)
Neo4J is mature not dated which is why it's so popular.

And couldn't disagree more that graph is a feature. You really want something optimised for it (query language / storage approach) as the data structure is so different in every way from a relational or document store.

Re:Postgres as a Graph Database: (Ab)Using PgRouting by tucnak on Friday February 28, 2025 @02:01AM (#43202583)
How is it different? Isn't a graph basically two sets of tuples: edges and nodes? I played with Cayley (Google) for a little while, & that was my impression.
Re:Postgres as a Graph Database: (Ab)Using PgRouting by bubblyworld on Friday February 28, 2025 @04:28AM (#43203580)
I think it's less a matter of "can you represent graphs in a relational DB" (of course you can), and more about what kind of queries the DB is optimised for. Graph databases are intended for complex recursive queries on relatively unstructured data. You could certainly do that in SQL if you wanted to, but you'll pay for it performance-wise.

Graph query languages also make those kinds of queries much easier to express in the first place.

Re:Postgres as a Graph Database: (Ab)Using PgRouting by tucnak on Friday February 28, 2025 @04:36AM (#43203631)
So the underlying storage is conventional, it's still tuples of some kind, and it's only a matter of how indexes are laid out? Otherwise, I'm struggling to see how it could "optimise" for certain access patterns. How would a typical graph database index be different from a btree access method in Postgres?
Re:Postgres as a Graph Database: (Ab)Using PgRouting by bubblyworld on Friday February 28, 2025 @05:00AM (#43203825)
I don't know much about the internal details of postgres. But there is a ton of detail underlying "it's just tuples of some kind" and there are lots of ways to implement indices, no? Is it so difficult to imagine that different implementations have different performance properties?

There's also the query planner layer to think about too.

Re:Postgres as a Graph Database: (Ab)Using PgRouting by tucnak on Friday February 28, 2025 @08:08AM (#43205182)
Thank you, I'm well aware that a class of software called "databases" exists
Re:Postgres as a Graph Database: (Ab)Using PgRouting by bubblyworld on Friday February 28, 2025 @08:38AM (#43205424)
No need for the snark. If you want specific details of how postgres differs from graph databases I have nothing for you. I just find your position that btrees are optimised for every query structure... obviously false on general grounds? Like a thing to do to make recursive queries faster is to store relations as direct pointers of some kind, rather than doing index scans for every level of join.

Perhaps we're talking past each other about the word "optimised".

Re:Postgres as a Graph Database: (Ab)Using PgRouting by tucnak on Monday March 03, 2025 @04:22AM (#43239941)
> I just find your position that btrees are optimised for every query structure

But that is not my position! Postgres has many index access methods: hash, btree, brin, gin, gist, and there are extensions for rum, bloom, skipscans, geospatial indexes such as sp-gist, & vector indexes like ivf/hnws (see pgvector.) I mean, as far as graph databases are concerned, besides pgRouting, there's also Apache AGE which is a graph-"optimised" Postgres.

You should learn more about Postgres and databases in general. See comment above. https://news.ycombinator.com/item?id=43203833 which is closely related to the argument I am actually making.

Re:Postgres as a Graph Database: (Ab)Using PgRouting by bubblyworld on Wednesday March 05, 2025 @11:56AM (#43269194)
Fair, and I apologise for misrepresenting it. I should definitely learn more about databases in general!
Re:Postgres as a Graph Database: (Ab)Using PgRouting by thesz on Friday February 28, 2025 @05:01AM (#43203833)
> ...as the data structure is so different in every way from a relational or document store.

No, it is not.

[1] https://en.wikipedia.org/wiki/Worst-case_optimal_join_algori...

Graph processing can create substantial amount of intermediate data if it is done in typical join implementation fashion (nested loops or hash join). So it may appear that graph processing needs a tailored approach.

But what can help graph algorithms can help SQL query execution as well and vice versa, see the link above.

For example, TPC-DS contains queries that (indirectly) joins same tables multiple times (query 4, for example). This is, basically, a kind of centrality metric computation for a graph represented by the tables.