Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-23-2021 03:29 PM
all below is using the legis-graph dataset available on Neo4j sandbox
Below are two queries that have tradeoffs between db hits and rows returned after each output. To reduce cardinality, it seems that the first query is more efficient. However, in terms of db hits, it seems the latter is more efficient. How does one decide which is most performant as the graph grows? That being said, it does seem that we should optimize for database hits, but I wanted to make sure that's the case
query 1
MATCH (b:Bill {billID:"hr1020-114"})
with b, [(b)<-[:VOTED_ON]-(v:Legislator) | v] as voters, [(b)-[:SPONSORED_BY]->(s:Legislator) | s] as sponsors
return b, voters, sponsors
query 2:
MATCH (b:Bill {billID:"hr1020-114"})
with b
MATCH p=(:Legislator)-[:VOTED_ON]->(b)-[:SPONSORED_BY]->(:Legislator)
return p
Also, if I'm not mistaken, it seems that the Expand(All) operation is an eager operator. Is it possible to rewrite the query without this eager operator?
Is there somewhere that lists what the various colors in the execution plan mean: light blue, dark blue, very dark blue? I dont see a description of why particular operations are light blue, blue and a darker blue (which is eager operator) much anywhere. In the same way that an Expand(All) is eager, a CartesianProduct is too, right?
01-26-2021 07:48 AM
Off topic a bit, but I'm curious, did query 2 really give the same answer as query 1?
Query 1 is matching partial paths
Query 2 must return a complete path form Legislator to Legislator.
Would you ever want to know if a bill is only VOTED_ON or only SPONSORED_BY? but not both?
FYI, I lean towards optimizing for row count, but the answer might be "it depends"
01-26-2021 10:52 AM
query 1
MATCH (s:Legislator)<-[:SPONSORED_BY]-(b:Bill {billID:"hr1020-114"})<-[:VOTED_ON]-(v:Legislator)
RETURN b AS Bill , v AS Voters, s AS Sponsors
query 2:
MATCH path = (:Legislator)<-[:SPONSORED_BY]-(b:Bill {billID:"hr1020-114"})<-[:VOTED_ON]-(:Legislator)
RETURN path
@Joel is right, if you except finding the Legislator who are sponsoring AND voted on a bill, none of these queries are doing it right now. But this one will:
MATCH (l:Legislator)<-[:SPONSORED_BY]-(b:Bill {billID:"hr1020-114"})<-[:VOTED_ON]-(l:Legislator)
RETURN l AS Legislator , b as Bill
All the sessions of the conference are now available online