A newbie in the space, could anybody see any way to improve this cypher performance?
match (tile:Tile) where tile.uuid = '517cce8d-1c2a-4fa5-b025-f76559bd579d'
optional match (tile)<-[*]-(l:Letter)
optional match (l)-[:HAS_DOC_TYPE]->(d:Document)
optional match (l)<-[:ENGAGEMENT_FOR]-(e:Engagement)
optional match (l)<-[:HAS_LETTER]-(p:Person)
optional match (l)<-[:CREATED_LETTER]-(c:Person)
with {name: tile.name, letter: collect(distinct d), document: d.name,
engagement: e.name, createdBy: collect(distinct c), team: collect(distinct p)} as stats
return {count: count(stats), data: collect(stats)}
bennu_neo
(Harold Agudelo-Ramirez)
July 13, 2022, 5:40pm
2
Well, it depends on your :Letter logic. How does your model look?
The way your query is defined, it will expand through every possible relationship (even if that means duplicating Nodes) and then filtering those with a ending node with a :Letter label.
Take a look into https://neo4j.com/labs/apoc/4.1/graph-querying/expand-subgraph/ . You may find a better way to this using the labelFilter properly.
Regards
bennu_neo
(Harold Agudelo-Ramirez)
July 13, 2022, 2:54pm
3
Hi @kasparov112000 ,
All the heavy computational part of this query is in
@kasparov112000 wrote:
optional match (tile)<-[*]-(l:Letter)
Couple of questions.
1. Why are you using the [*], don't you have at least a particular type of relationship/pattern in order to arrive to the :Letter?
2. Is your subgraph expansion stopping for every path on the first :Letter or is expecting to find another one after?
3. Is APOC installed on your db instance?
Regards
B
Thanks for the assistance , below is the shape.
I tried using the apoc library, but does not seem to yield all the data:
match (tile:Tile) where tile.uuid = '517cce8d-1c2a-4fa5-b025-f76559bd579d'
CALL apoc.path.subgraphAll(tile, {
relationshipFilter: "KNOWS",
minLevel: 1,
maxLevel: 100
})
YIELD nodes, relationships
optional match (l)-[:HAS_DOC_TYPE]->(d:Document)
optional match (l)<-[:ENGAGEMENT_FOR]-(e:Engagement)
optional match (l)<-[:HAS_LETTER]-(p:Person)
optional match (l)<-[:CREATED_LETTER]-(c:Person)
with {name: tile.name, letter: collect(distinct d), document: d.name,
engagement: e.name, createdBy: collect(distinct c), team: collect(distinct p)} as stats
return {count: count(stats), data: collect(stats)}
Yes APOC is installed. (tile)<-[*]-(l:Letter), I am trying to understand or learn, is there any query that may produce all the possible paths/patterns?
bennu_neo
(Harold Agudelo-Ramirez)
July 13, 2022, 10:51pm
6
Well @kasparov112000 , you don't seem too have any KNOWS relationships. On your example, which one is the tile? From tile to :LETTER , do you know anything about the relationship that are in the middle? Maybe the type and direction? That way you can specify them in order to avoid cycles.