neo4j/neo4j — pull request #2599 by boggle (2014-06-23 13:05:32+00:00)
Title: Pattern expression bug

Some context:

Query

MATCH (owner) WITH owner, COUNT(*) AS collected WHERE (owner)--() RETURN *

Expected

GIVEN * MATCH (owner) WITH owner AS `owner`, count(*) AS `collected`
GIVEN *
WHERE
Predicate[owner
](
PatternExpression(
RelationshipsPattern(
RelationshipChain(
NodePattern(Some(owner), ⬨, None, false),
RelationshipPattern(Some( UNNAMED61), false, ⬨, None, None, OUTGOING
),
NodePattern(Some( UNNAMED65), ⬨, None, false)
)
)
)
)
RETURN owner AS `owner`

Yet post aggregation this happens:

QueryPlan(
Apply[owner,collected]()
↳ left =
Aggregation[owner,collected
](Map("owner" → owner), Map("collected" → count(*))
)
↳ AllNodesScan[owner](owner)
↳ right = SingleRow[](Set()),
GIVEN * MATCH (owner) WITH owner AS `owner`, count(*) AS `collected`
GIVEN * RETURN *
)

applySelections

QueryPlan(
SemiApply[owner,collected]()
↳ left =
Apply[owner,collected]()
↳ left =
Aggregation[owner,collected
](Map("owner" → owner), Map("collected" → count(*))
)
↳ AllNodesScan[owner](owner)
↳ right = SingleRow[](Set())
↳ right =
Expand[owner, UNNAMED61, UNNAMED65
](owner, OUTGOING, ⬨, UNNAMED65, UNNAMED61
)
↳ SingleRow[owner](Set(owner)),
GIVEN *
MATCH (owner)
WHERE
Predicate[owner
](
PatternExpression(
RelationshipsPattern(
RelationshipChain(
NodePattern(Some(owner), ⬨, None, false),
RelationshipPattern(
Some( UNNAMED61),
false,
⬨,
None,
None,
OUTGOING
),
NodePattern(Some( UNNAMED65), ⬨, None, false)
)
)
)
)
WITH owner AS `owner`, count(*) AS `collected`
GIVEN * RETURN *
)

Why?

well we planSemiApply the patten predicate on top of

QueryPlan(
Apply[owner,collected]()
↳ left =
Aggregation[owner,collected
](Map("owner" → owner), Map("collected" → count(*))
)
↳ AllNodesScan[owner](owner)
↳ right = SingleRow[](Set()),
GIVEN * MATCH (owner) WITH owner AS `owner`, count(*) AS `collected`
GIVEN * RETURN *
)

instead of adding it to the tail (which is wrong). This PR fixes that.