Summary
WITH ... ORDER BY ... LIMIT k followed by another MATCH is rejected when the prefix produces multi-row results — ordering / limit are not preserved across the MATCH re-entry. This blocks the LDBC SNB IC1 ordered-top-k friend tail.
Repro (minimal, fails on master 41d865ac9)
MATCH (p:Person {id: $pid})-[:KNOWS]-(friend)
WITH friend
ORDER BY friend.firstName ASC
LIMIT 5
MATCH (friend)-[:STUDY_AT]->(uni:University)
RETURN friend.id AS friendId, uni.name AS uniName
Expected vs observed
- Expected: top-5 friends by
firstName survive the LIMIT; the trailing MATCH expands STUDY_AT for that subset.
- Observed:
GFQLValidationError: [unsupported-cypher-query] Cypher MATCH after WITH does not yet preserve prefix WITH row ordering across MATCH re-entry for multi-row result shapes | field: with.order_by | value: ['friend.firstName']
Source
- Guard:
graphistry/compute/gfql/cypher/reentry/runtime.py:340
- Helper:
_bounded_reentry_prefix_order_is_safe (same file)
- Asserting tests:
graphistry/tests/compute/gfql/cypher/test_lowering.py:9218, :9226
Benchmark evidence
pyg-bench artifact: results/runs/dgx-spark-ic1-conformance-2026-04-05/probe-results.json
- LDBC SNB lane:
interactive-complex-1 / named-shortest-friends
- Official IC1 query has
WITH min(length(path)) AS distance, friend ORDER BY distance ASC, friend.lastName ASC, toInteger(friend.id) ASC LIMIT 20 immediately followed by another MATCH (friend)-[:IS_LOCATED_IN]->(friendCity:City).
Acceptance criteria
- The minimal repro above succeeds with the trailing MATCH applied to exactly the top-5 friends ordered by
firstName.
- ReentryPlan (or the bounded-reentry runtime) preserves
prefix.order_by and prefix.limit through the trailing MATCH for multi-row prefixes.
- Regression tests cover: ORDER BY single column + LIMIT, ORDER BY multi-column + LIMIT, ORDER BY DESC + LIMIT, all followed by re-MATCH that traverses out from the carried alias.
Subsystem / scope
graphistry/compute/gfql/cypher/reentry/runtime.py (_bounded_reentry_prefix_order_is_safe, the surrounding admit logic)
graphistry/compute/gfql/cypher/reentry_plan.py (carry-set + ordering metadata)
- Out of scope: ordering across more than one re-entry hop — that is a follow-up.
Related
Summary
WITH ... ORDER BY ... LIMIT kfollowed by anotherMATCHis rejected when the prefix produces multi-row results — ordering / limit are not preserved across the MATCH re-entry. This blocks the LDBC SNB IC1 ordered-top-k friend tail.Repro (minimal, fails on master
41d865ac9)Expected vs observed
firstNamesurvive the LIMIT; the trailing MATCH expandsSTUDY_ATfor that subset.GFQLValidationError: [unsupported-cypher-query] Cypher MATCH after WITH does not yet preserve prefix WITH row ordering across MATCH re-entry for multi-row result shapes | field: with.order_by | value: ['friend.firstName']Source
graphistry/compute/gfql/cypher/reentry/runtime.py:340_bounded_reentry_prefix_order_is_safe(same file)graphistry/tests/compute/gfql/cypher/test_lowering.py:9218,:9226Benchmark evidence
pyg-benchartifact:results/runs/dgx-spark-ic1-conformance-2026-04-05/probe-results.jsoninteractive-complex-1/named-shortest-friendsWITH min(length(path)) AS distance, friend ORDER BY distance ASC, friend.lastName ASC, toInteger(friend.id) ASC LIMIT 20immediately followed by anotherMATCH (friend)-[:IS_LOCATED_IN]->(friendCity:City).Acceptance criteria
firstName.prefix.order_byandprefix.limitthrough the trailing MATCH for multi-row prefixes.Subsystem / scope
graphistry/compute/gfql/cypher/reentry/runtime.py(_bounded_reentry_prefix_order_is_safe, the surrounding admit logic)graphistry/compute/gfql/cypher/reentry_plan.py(carry-set + ordering metadata)Related