Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-29-2022 07:23 PM
Given a database with thousands of nodes:
MERGE (n1:Node {id:1});
MERGE (n2:Node {id:2, first:"John", last:"Doe"});
I want to construct a SCALABLE query that returns nodes if any 1 of the following conditions applies:
I have come up with the following query but it threw an out-of-memory error when the number of conditions reached 10,000
WITH [
{id: 12, first: "Turkey", last: "Legs"},
{id: 12, first: "John", last: "Doe"},
{id: 1, first: "Jiggly", last: "Puff"}
// thousands more
] AS conditions
UNWIND conditions AS condition
MATCH (n:Node) WHERE node.id = condition.id) AND (n.first = condition.first AND n.last = condition.last)
RETURN collect(DISTINCT n)
Just in case you are wondering, I have added indices and composite indices where needed
09-29-2022 07:51 PM
IMHO , this is not graph traversal and you are just trying with typical SQL way of scanning the entire table based on Index filter . When you say 1000 more such conditions, we need to have labels or relationship based on the conditions .
Wud be great to understand your problem statement more . Is it like you want to check Friend of Friend network at Hops level?
Cant we label the Generic name 'Node' to differentiate with 'SpecialNode' | ' General' | 'Churn' and using sub query you can consolidate the results from different labels of Node
Check this apoc.path.expand - APOC Documentation (neo4j.com)
09-29-2022 08:03 PM
yes, you are correct it's more of a typical SQL way of scanning the entire table based on index filter. There are no graph traversals in the query that I am trying to construct, thus the conditions have no labels nor relationships. All nodes are assumed to be the same label (i.e. Node in this case).
You may be wondering why use Neo4j instead of an SQL database, well this is a subproblem extracted from a much larger graph database with different node labels and relationships. But I left that out since it wasn't needed as part of the question
09-29-2022 08:24 PM
Do you run out of memory if you return ‘n’ , without the collect and distinct?
10-02-2022 09:44 AM
Yes I ran it without collect(DISTINCT ?) and it still ran out of memory.
10-02-2022 10:22 AM
Can you post the query plan. You insert ‘explain’ at the beginning of the query. There will be a new ‘Plan’ icon in the list of output formats.
All the sessions of the conference are now available online