Compiler CYPHER 4.1
Planner COST
Runtime INTERPRETED
Runtime version 4.1
+-----------------+-------------------------------------------------------------------------------------------------+----------------+------+---------+-----------------+-------------------+----------------------+
| Operator | Details | Estimated Rows | Rows | DB Hits | Page Cache Hits | Page Cache Misses | Page Cache Hit Ratio |
+-----------------+-------------------------------------------------------------------------------------------------+----------------+------+---------+-----------------+-------------------+----------------------+
| +ProduceResults | person | 1 | 1 | 0 | 0 | 0 | 0.0000 |
| | +-------------------------------------------------------------------------------------------------+----------------+------+---------+-----------------+-------------------+----------------------+
| +NodeIndexSeek | person:Person(firstname, surname) WHERE firstname STARTS WITH $autostring_0 AND exists(surname) | 1 | 1 | 2 | 0 | 0 | 0.0000 |
+-----------------+-------------------------------------------------------------------------------------------------+----------------+------+---------+-----------------+-------------------+----------------------+
Total database accesses: 2, total allocated memory: 0
Second question: I create an index on id, but it seems not working.
CREATE INDEX ON :Artifact(id)
Then I execute this cypher:
explain Match (some:Artifact)-[:DEPEND_ON*]->(a:Artifact {gav:"org.slf4j:slf4j-api:1.7.21"}) where not exists(()-[:DEPEND_ON]->(some)) and 0<ID(some)<1000 return distinct some.gav
The requirement is to query all the Artifact nodes that directly or indirectly depend on the Artifact with gav:org.slf4j:slf4j-api:1.7.21 .
This graph is built up from a Maven Central Repository (which is a java library repository). And the org.slf4j:slf4j-api:1.7.21 Artifact has a tons of other Artifacts depend on it either directly or indirectly.
The simplest data model is like this:
My solution for the requirement is like this:
Step 1: Find all the Artifact nodes which don't have other Artifacts depend on them. Cause if they have, it makes these nodes also depend on org.slf4j:slf4j-api:1.7.21. get result a.
Step 2: Filter the result a to get which of them truly depend_on* org.slf4j:slf4j-api:1.7.21. get result b.
Cyher
Match (some:Artifact) where 0<id(some)<1000 and not exists(()-[:DEPEND_ON]->(some))with collect(some) as col
Match (a:Artifact) where id(a)=179110 with a
FOREACH (n IN col| match p=shortestpath((n)-[:DEPEND_ON*]->(a))
return case p when p then n end AS result)
Step 3: Iterate the result b to get the distinct nodes in all the paths between every nodes in result b to org.slf4j:slf4j-api:1.7.21. That's the final result for the requirement.
e.g.
match (a:Artifact {gav:"net.wessendorf.kafka:kafka-cdi-extension:0.0.9"}) ,(b:Artifact {gav:"org.slf4j:slf4j-api:1.7.21"}),p=allshortestpaths((a)-[:DEPEND_ON*]->(b)) return p
I also tried skip...limit to implement pagination before, But when the skip number goes up, the query tended to extremely slow.
MATCH (a:Artifact {gav: "org.slf4j:slf4j-api:1.7.21"})<-[:DEPEND_ON*]-(some)
where a<>some return distinct some skip n limit m
I would like to ask if there is any other better way to do this work.
Or how can I make my cypher above executable?
MATCH (some:Artifact)
WHERE 0 < id(some) < 1000 and not ()-[:DEPEND_ON]->(some)
WITH collect(some) as col
MATCH (a:Artifact)
WHERE id(a)=179110
WITH a, col
UNWIND col as n
MATCH p = shortestpath((n)-[:DEPEND_ON*]->(a))
RETURN CASE p WHEN p THEN n END AS result
Though I'm not sure it will do what you want. I'm not quite sure what you're intending by that RETURN.
The requirement is to query all the Artifact nodes that directly or indirectly depend on the Artifact with property gav: org.slf4j:slf4j-api:1.7.21 .and its id is 179110
I want to get all the nodes like the diagram below.
This graph is built up from a Maven Central Repository (which is a java library repository). And the org.slf4j:slf4j-api:1.7.21 Artifact has a tons of other Artifacts depend on it either directly or indirectly.
Do you need paths to each of these nodes, or do you just need the nodes?
You also did some pre-matching based on ids. Is that still needed, or is it enough to get all connected :Artifact nodes that don't have anything depending on them?
Hi, Andrew,
I want to get all the :Artifact nodes related to the target node. Not only the nodes that don't have anything depending on them but also these nodes in the paths the start nodes to target nodes in this diagram, excluding the target node.
In a word, all the :Artifact nodes depending on the target node either directly or indirectly.
And it's quite efficient:
Started streaming 164139 records after 6 ms and completed after 9674 ms, displaying first 1000 rows.
One more question:
How can I get the execution time of cypher and the memory allocated on the neo4j desktop?
Or are there any other ways to get these data?
I used profile match ..., but cannot get the total allocated memory.
I want to get the information like below. My neo4j version is 3.5.15