Count all relationships by a property

mr_sheehan
Node
MATCH (:A)-[r]->(:A)
RETURN r.myProp as prop, count(r) as count

I'm wondering if there is a way to speed up this query. Currently with ~50 million relationships, it takes a long time.

1 REPLY 1

Reiner
Graph Buddy

Hi @mr.sheehan,
welcome to the community!

Depends on the structure of your graph. My first hint would be to add a type to the relationship, cause I assume myProp doesn't appear on all types of relationships but on one or only a few.

MATCH (:A)-[r:REL_TYPE]->(:A) ...

or, if more than one type is needed:

MATCH (:A)-[r:REL_TYPE1|RELTYPE2]->(:A) ...

Best,
Reiner