0
votes

I have this query in my app:

MATCH (ctx:Context{uid:"c1af16f0-f2fa-11e3-a477-6749dbdfc34e"}), 
c-[at:AT]->ctx, 
s-[in:IN]->ctx, 
ctx-[by:BY]->u 
WITH c,at,s,in,ctx,by,u 
MATCH con-[byc:BY]->u 
WHERE byc.statement = s.uid 
DELETE at,in,s,byc

And it's taking ages to execute. I thought it was because of the WHERE clause, but no, even if I get rid of the WITH and go directly to DELETE, such as

MATCH (ctx:Context{uid:"c1af16f0-f2fa-11e3-a477-6749dbdfc34e"}), 
c-[at:AT]->ctx, 
s-[in:IN]->ctx, 
ctx-[by:BY]->u 
DELETE at,in,s

It's still taking too long.

It's a lot of nodes to delete (hundreds), but still, maybe I'm just doing something wrong with the query?

Let me know, please...

The basic idea is to find a node, then find all the other ones connected to it, delete those relationships, and only one type of connected nodes.

Thank you!

1
provide the query profile using in neo4j-shell: profile match(.....) - Stefan Armbruster
You don't say that you have an index on :Context(uid). Do you? Profile would help. - Eve Freeman
@WesFreeman i do have an index on Context(uid), can't really do profile because it's taking so long... - Aerodynamika
does the JVM show GC issues? If so apply LIMIT and SKIP to have a smaller transaction size. - Stefan Armbruster
@StefanArmbruster thanks, for now i solved the issue by splitting the query into several. - Aerodynamika

1 Answers

0
votes

Try something like this that will get less expansion of products:

MATCH (ctx:Context{uid:"c1af16f0-f2fa-11e3-a477-6749dbdfc34e"})<-[in:IN]-(s)
WITH ctx, collect(s.uid) as uids
MATCH (ctx)<-[in:IN]-(s)
DELETE s, in
WITH DISTINCT ctx, uids
MATCH (ctx)<-[at:AT]->()
DELETE at
WITH DISTINCT ctx, uids
MATCH (con)-[byc:BY]->()
WHERE byc.statement in uids 
DELETE byc