Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-10-2022 08:54 AM
I'm using a database from a particular Udemy course. When I run MATCH (x)--(y)-->(z) RETURN x, y, z LIMIT 2
I get
and when I run MATCH (x)--(y)-->(z) RETURN x, y, z LIMIT 3
(2 -> 3) I get
As I see it, there are already three, non-repeat instances of (x)--(y)-->(z) in the first diagram—see my graphical annotation—so I don't understand why Neo4j sees the need to add more nodes for the second query. Obviously this means that I don't understand Cypher semantics; I would appreciate it if you would replace my incorrect understanding with a correct one.
Solved! Go to Solution.
02-10-2022 09:53 AM
Exactly. There were other paths that got determined first and those in diagram did not all make your limit of 3.
02-10-2022 09:14 AM
When you show the results as a graph in the browser, it seems neo4j shows the nodes that result and all the connections among those nodes. Try viewing your results using the 'text' or 'table' renderings. You will probably be shown the proper number of paths.
02-10-2022 09:23 AM
Not sure what you're saying, but it looks like you're saying that it would make the x, y, z triples that are matched explicit? It might not dispel my doubts, but it's a good idea; will do
02-10-2022 09:27 AM
The graph rendering seems to show all the nodes that resulted from your query, and displays them will all their connections, regardless if they are part of your result.
The text and table renderings show the explicit result by row; therefore, you should see two results in your first query and three results in the second. If you want to see the connections between them too, you could write the query to return the paths instead of the individual nodes, such as:
MATCH p = (x)--(y)-->(z) RETURN return p LIMIT 3
02-10-2022 09:30 AM
I have three results in the second query, but those three results collectively involve five nodes which is what's unexpected
02-10-2022 09:41 AM
You did not put any constraints on the nodes, so it gave you the first three paths it determined. I just so happens that these paths consisted collectively of 5 nodes. There must be many paths in this data set to choose from. It wasn't guaranteed that you would have gotten the three paths you highlighted in your first diagram, since they are more than three in your dataset. You could get those three if you constrained your node y to be Keanu Reeves (again, assuming there are not more paths traversing through Keanu Reeves)
Add a SKIP clause, and you will get a different set of three paths (assuming you have 6 or paths)
MATCH p = (x)--(y)-->(z)
RETURN return p
SKIP 3
LIMIT 3
02-10-2022 09:52 AM
That makes sense, thanks. So the second query's diagram could've matched the first query's diagram, but it just so happened that it didn't?
02-10-2022 09:53 AM
Exactly. There were other paths that got determined first and those in diagram did not all make your limit of 3.
02-10-2022 09:58 AM
I made an implicit assumption that because the first two paths were enough to form a third, Cypher would just use that third
02-10-2022 09:40 AM
@glilienfield I guess there's a rule that any match to a MATCH
query must consist of at least one component (node or relationship) that doesn't form part of the other matches?
02-10-2022 09:51 AM
there is no constraint imposed between the results. Each just has to meet the conditions of the query. Try removing the LIMIT clause, so you see all paths that meet your match pattern.
This is a good reference about path matching:
All the sessions of the conference are now available online