7vingt
7vingt

Reputation: 301

Neo4j count number of relationships complexity

i'am wondering how neo4j interpretes this request in background :

start n=node(500) match n-[:relation_type]-() return count(*)

Does Neo4j iterates on all the relation_type to have the count or does it maintains a counter of all elements for each "internals linked lists of typed relation"?

I wondering if i have to store the number of relations in a property each time i add one, or if i can retrieve it quickly without making neo4j iterates on all relations to have the current count.

(like in mysql : 'select count(*)' does not go threw all the rows, it knows the number of lines in a table, does neo4j knows the number of typed relation for a given node?)

Thank you for you help!

Upvotes: 2

Views: 2285

Answers (1)

bendaizer
bendaizer

Reputation: 1235

Wonder no more for you can use the cypher profiler to see what's going on with your cypher queries :)

You can use cypher in the neo4j-shell, and precede it with the "profile" keyword (only for neo4j 1.9 and 2.0 though).

You can try it in the neo4j-shell provided in the webadmin interface:

profile start n=node(500) match n-[:relation_type]-() return count(*);

I tried with something similar and got the following output:

==> ColumnFilter(symKeys=["  INTERNAL_AGGREGATEb12550d5-63c6-41c4-a4b5-86bba011c998"], returnItemNames=["count(*)"], _rows=1, _db_hits=0)
==> EagerAggregation(keys=[], aggregates=["(  INTERNAL_AGGREGATEb12550d5-63c6-41c4-a4b5-86bba011c998,CountStar)"], _rows=1, _db_hits=0)
==>   TraversalMatcher(trail="(n)-[  UNNAMED6:LIKE WHERE true AND true]->(  UNNAMED5)", _rows=25, _db_hits=26)
==>     ParameterPipe(_rows=1, _db_hits=0)

which makes me think that it counts as it is traversing (starts with _db_hits = 0)!

Upvotes: 2

Related Questions