How to optimize execution time for this simple request?

Context : I have around 360million of relationships for 27 types of relation. No constraints were created.

work : I want to browser all of them to update data with apoc.periodic.iterate and the cypher request of the first parameter is MATCH ()-[r]->() where r.prop IS NOT NULL return r
The second part of iterate procedure do a updating data.

How to optimize? the "MATCH.." cypher request, may be creating some constraints or modify file configuration?

Advance thanks

You can use:

EXPLAIN <your query>

You probably need to create indexes too:

Here is the explain output... but what am I supposed to understand by that?

Thank you

Unfortunately, the EXPLAIN plans do not always provide insight when using APOC procedures, as these procedures are executed on the server using the native Java API. It's like a black box to the query planner.

I am not sure indexes will be practical in this case, as an index is specific to a relationship type. In your case, you stated there are 27 different relationship types. As such, you would need an index for each relationship type. There are two ways you could write query. Each seems to utilize the individual indexes.

Using a relationship type predicate to account for each relationship type:

Using a UNION to account for each relationship type:

You can also use either of the two approaches above without indexes (if it is impractical to create indexes), but you would get a full table scan. You could simplify the query in this case if the number of relationships outside the 27 is much smaller by using a relationship predicate that excludes the few outside the relationship types to update.

BTW- you could use neo4j's CALL Subquery in Transactions instead of the APOC periodic iterate. It now supports concurrent execution.

1 Like

Thank you very much!

It's much better to proceed by type of relationship.