When to combine queries and when to split them up?

20 views
Skip to first unread message

Mat Tyndall

unread,
Aug 21, 2012, 9:56:48 PM8/21/12
to ne...@googlegroups.com
I've been experimenting writing cypher queries 2 ways when I need to create/modify many nodes and set properties on each.

One way is to combine all the commands together so I get something like this:

query = 'START root=node(0) CREATE UNIQUE root-[:test]->(a {name:{a_name}}), root-[:test]->(b {name:{b_name}}) SET a.prop = {a_prop}, b.prop = {b_prop} RETURN a, b'

params = {
  a_name  : 'a'
  , a_prop  : 1
 , b_name : 'b'
 , b_prop   : 2
}

The other way is to asynchronously call a simple function that creates with each set of properties for a node.

The reason why I set some properties rather than put them into create unique is that only set allows me to update properties on an existing node.

So my question, is one way better than the other?

Is there a way I could do this more efficiently?

I also have a slightly more complicated query that I'll have to post later.

Thanks,

-Mat

Michael Hunger

unread,
Aug 21, 2012, 10:31:20 PM8/21/12
to ne...@googlegroups.com, do...@neo4j.org
In general it is more performant to have larger transactions (up to 10k elements).

The fine-grained setting of properties will hurt your throughput in the long run.

So it makes sense to either have larger cypher statement (or lists of parameters and then use foreach).
Or even to batch-cypher statements using the neo4j-rest-batch operations.

HTH

Michael
> --
>
>

Mat Tyndall

unread,
Aug 22, 2012, 5:23:49 AM8/22/12
to ne...@googlegroups.com, do...@neo4j.org
So if I want to do with with foreach, any suggestions for how to group the paramaters?

From what I can tell, I could group all the properties for a node in an array like:

PROPS : [[1,1,1],[2,2,2],[3,3,3]]

then: FOREACH( x in {PROPS} : set n.test = HEAD(TAIL(x)) )

but the problem is that I can't seem to chain head and tail properly to pull out x[1] (head and last by themselves work fine though). I can't pass an array of objects in params because cypher won't let me use dot notation so...

I'm thinking this foreach thing is more trouble than it's worth, probably just going to go back to building queries by adding strings onto the end of each part of the query.

-Mat

Michael Hunger

unread,
Aug 22, 2012, 7:56:36 AM8/22/12
to ne...@googlegroups.com
Mat,

you're right,

can you raise an issue for this? Thanks a lot.

Michael

--
 
 

Reply all
Reply to author
Forward
0 new messages