Live data from Hacker News

Apache AGE, a PostgreSQL extension with graph database functionality

github.com

11–20 of 77 posts

Re: Apache AGE, a PostgreSQL extension with graph database functionality

#11

Could it be efficient to use Apache AGE for e.g. retrieving all comments on an article? Currently I’m using materialized paths to efficiency return all commments but would be keen to know if AGE can help query comments for an article more powerfully.

Have you tried recursive CTEs with a simple id, parent_id etc schema? These should perform very well if those columns are in an index.

Afaik this is pretty much the canonical way to store recursive comment trees. Or any kind of DAG.

Re: Apache AGE, a PostgreSQL extension with graph database functionality

#12

Could it be efficient to use Apache AGE for e.g. retrieving all comments on an article? Currently I’m using materialized paths to efficiency return all commments but would be keen to know if AGE can help query comments for an article more powerfully.

Have you tried recursive CTEs with a simple id, parent_id etc schema? These should perform very well if those columns are in an index. Afaik this is pretty much the canonical way to store recursive comment trees. Or any kind of DAG.

AGE can handle that and recursive ctes can as well, but AGE has mechanisms to handle cyclic graphs as well.

Re: Apache AGE, a PostgreSQL extension with graph database functionality

#13
post #5

Anyone tried this? How does the performance compare to neo4j and RedisGraph? I’m about to give RedisGraph a try and I guess I will try this one a go as well.

AGE 1.1 should perform better or at least similar to Neo4j. Not sure about RedisGraph.

Re: Apache AGE, a PostgreSQL extension with graph database functionality

#14

Could it be efficient to use Apache AGE for e.g. retrieving all comments on an article? Currently I’m using materialized paths to efficiency return all commments but would be keen to know if AGE can help query comments for an article more powerfully.

Have you tried recursive CTEs with a simple id, parent_id etc schema? These should perform very well if those columns are in an index. Afaik this is pretty much the canonical way to store recursive comment trees. Or any kind of DAG.

This comment gave me a flashback to Celko's SQL for Smarties. I believe the updated books are split off into a few smaller books? But the section/book on trees in a relational database helped me greatly once in a galaxy far far away.

Re: Apache AGE, a PostgreSQL extension with graph database functionality

#15

Could it be efficient to use Apache AGE for e.g. retrieving all comments on an article? Currently I’m using materialized paths to efficiency return all commments but would be keen to know if AGE can help query comments for an article more powerfully.

Have you tried recursive CTEs with a simple id, parent_id etc schema? These should perform very well if those columns are in an index. Afaik this is pretty much the canonical way to store recursive comment trees. Or any kind of DAG.

Why not a trigger that maintains this in a simpler query in a separate table? Sounds more performant to me!

Recursive CTEs sounds like something you would do if your total comment count in the db is not in the six figures or something. What does HN do?

Re: Apache AGE, a PostgreSQL extension with graph database functionality

#16

Could it be efficient to use Apache AGE for e.g. retrieving all comments on an article? Currently I’m using materialized paths to efficiency return all commments but would be keen to know if AGE can help query comments for an article more powerfully.

I once achieved it by setting a parent_id string column - for root comments it’ll just be article id. For replies it’ll be “parent_comment.parent_id || parent_comment.id”. Then it’s just a single list no recursion needed to get the full hierarchy at whatever level. Can also be easily migrated to dynamodb and get infinite scaling and zero downtime costs.

Re: Apache AGE, a PostgreSQL extension with graph database functionality

#20

Could it be efficient to use Apache AGE for e.g. retrieving all comments on an article? Currently I’m using materialized paths to efficiency return all commments but would be keen to know if AGE can help query comments for an article more powerfully.

Have you tried recursive CTEs with a simple id, parent_id etc schema? These should perform very well if those columns are in an index. Afaik this is pretty much the canonical way to store recursive comment trees. Or any kind of DAG.

As long as comments are a tree, there’s only one path from the root (the post) to an individual comment. How would a recursive CTE perform better than a prefix scan on an indexed string column?

Storing a pointer to each node’s parent or using sorted sets seems like it would make the parent poster’s query slower. Those approaches would make it easier to reparent comments, though, and they’d support arbitrarily deep trees (whereas the materialized path implementations I’ve seen limit path length).

Post reply on HN