Cypher: dynamic START clauses? (ID or index query)

40 views
Skip to first unread message

Aseem Kishore

unread,
Dec 24, 2012, 3:43:07 PM12/24/12
to Neo4j Discussion
Is there any way to have a dynamic START clause, where the node/rel ID or index query comes from a preceding WITH?

(You can of course parametrize the START clause; I mean where the value isn't known in advance, but rather derived within the query itself.)

Here's the scenario I'm thinking of: node A is a supernode with a million relationships of type X, and just one of type Y. We want to follow the Y relationship efficiently.

We could use a global relationship index to index that Y relationship with something associating it to node A.

But in the spirit of graph databases ("index-free adjacency"), I was wondering why not store the Y relationship's ID as a property on node A? Then you could efficiently fetch the Y relationship if you had node A.

I presume I could do this in Gremlin, but I was hoping it'd be possible in Cypher. Something like:

START n=node({id})
WITH n, n.yRelId as yRelId
START r=relationship(yRelId)
MATCH n -[r]-> foo
RETURN foo

(I'm assuming btw that `MATCH n -[r]-> foo` will be optimized to not scan all of n's relationships if `r` is already a START point. I hope that's indeed the case?)

If this isn't possible today, please consider this a feature request. =) Happy to file an issue if so.

Thanks!

Aseem




Michael Hunger

unread,
Dec 24, 2012, 5:14:29 PM12/24/12
to ne...@googlegroups.com
Right now, neither node() nor relationship() take expressions as parameters, I think that is a sensible feature request, please file it on GitHub

Michael
> --
>
>

Reply all
Reply to author
Forward
0 new messages