Hi there,

How Cypher planning is done is something we are spending considerable
energy in improving right now, actually.

Long story short - your query is really bad for performance. Cypher is not
clever enough to realise that it's doing a lot of unnecessary work.

When you pull in things in the MATCH clause, the number of matches is
influenced, even if you don't include it in the RETURN clause. In this
particular query, you get around that by using collect(distinct aka), but
that's a rare edge case that we haven't taught Cypher to look for.

So, to answer your question, Cypher will match your whole pattern, even if
it's not strictly needed, and then return what you ask for in RETURN. We're
making the planner much smarter, but this is a little bit of an edge case,
so I don't expect it to be something we work on in the immediate future.

HTH,

Andrés


On Fri, Mar 7, 2014 at 3:35 AM, Rajeev Joseph <[email protected]>wrote:

> Hi guys,
>
> The below query matches a whole lot of nodes but only returns a few.
>
> I would like to know how neo4j processes the query internally. Mainly,
> will neo4j first fetch all the nodes from the MATCH statement and then
> return the ones we need or does it optimise the query first by looking at
> the RETURN statement and matching only the ones that makes sense. I'm
> concerned about performance.
>
> I appreciate that a query like the below with redundant matches doesn't
> make much sense. The reason we have such queries is that we construct
> queries for complex models in our code, rather than hand crafting each
> individual query.
>
> Example of a query I'm concerned about:
>
> START root=node(0)
> MATCH
> root-[:HAS_PERSON]-person,
> person-[?:HAS_LANGUAGE]-lang,
> person-[?:HAS_ETHNICITY]-ethnicity,
> person-[?:HAS_OFFENCE]-offence,
> person-[?:HAS_AKA]-aka,
> person-[?:HAS_EMAIL]-email,
> person-[?:HAS_PHONE]-phone,
> person-[?:HAS_ADDRESS]-address
> WHERE person.Id = 123
> RETURN person, collect(distinct aka)
>
>  --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.
>



-- 
The best way to ask for Cypher help: http://console.neo4j.org/usage.html

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to