We are running a lot of operations where the first statement in each is to get the set of nodes to operate on. For many, its the same set of nodes over and over again. Its not predictable time to time so its not something I can just assign an attribute for. Normally, I just have a starting node, run the tree and collect all the subnodes. Then I run about 106 different cypher statements on that collection.
But each query has to "re collect" the nodes. That seems like a waste of time since its the same nodes the previous query collected. I could add a temporary attribute to make it simpler to find but that doesn't seem terribly efficient either.
Is there a way to create a set of nodes in a variable and have that variable persist query to query ?
Solved! Go to Solution.
Others have made good suggestions for aliasing and subqueries, provided that you can do all you need to in a single query.
If you need to process across multiple queries and transactions, you could always add a temporary label to all the nodes you need to work with, and for the remainder of the queries use that temporary label in your matches so you're always working with the same nodes. You'll just need to remember to remove the label when you're done, and ensure no other queries can come along and modify the labels while you're processing.