Question about ordering of return results

16 views
Skip to first unread message

Alan Robertson

unread,
May 30, 2013, 10:11:37 PM5/30/13
to Neo4J
Hi,

As some of you may recall, I have a number of circular relationships in
my database - where each node has a single relationship to a subsequent
node in the graph, until finally the relationship returns to the
original node - completing the cycle.

Here's my query:
START Drone=node:Drone(Drone="drone000001")
MATCH p=Drone-[:RingNext_The_One_Ring*]->NextDrone
RETURN NextDrone.name, NextDrone

I get the nodes in the ring - in order of where they are on the ring.
This is a nice property.

It seems a perfectly rational result - that those with the shortest path
length appear first and those with the longest path length appear last
(after all, that's the order you have to discover them in - for this case).

The question is: Can I rely on this behavior?

--
Alan Robertson <al...@unix.sh> - @OSSAlanR

"Openness is the foundation and preservative of friendship... Let me claim from you at all times your undisguised opinions." - William Wilberforce

Andres Taylor

unread,
Jun 1, 2013, 7:34:45 AM6/1/13
to neo4j

Strictly speaking - no. If you want to receive paths in a certain order you should use order by.

Pragmatically speaking - I don't think this will vary as long as you don't upgrade to a new version. When you do, you should probably test this behavior extensively. Order by will make your query much slower, and it's probably safe to skip it.

Is that too vague?

Andrés

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Alan Robertson

unread,
Jun 6, 2013, 6:26:09 PM6/6/13
to ne...@googlegroups.com, Andres Taylor
On 6/1/2013 5:34 AM, Andres Taylor wrote:
>
> Strictly speaking - no. If you want to receive paths in a certain
> order you should use order by.
>
> Pragmatically speaking - I don't think this will vary as long as you
> don't upgrade to a new version. When you do, you should probably test
> this behavior extensively. Order by will make your query much slower,
> and it's probably safe to skip it.
>
> Is that too vague?
>

Well... I want my software to work and keep on working...

So you're saying that this might break in the future.

It's actually worse than that - I have to retain the path, and then sort
by the length of the path - which presumably is even more expensive than
merely a semi-normal order by. There is no reasonable way to compute
this in any other order -- so you would have to deliberately perturb the
order - or store it in a hash table or something in order for this to fail.

Right now, I'm not doing this in production -- but that might change -
although it will be mainly for testing of my code. But it did occur to
me to ask.

-- Alan Robertson
al...@unix.sh

Reply all
Reply to author
Forward
0 new messages