Repository navigation
perf(#12149): openCypher starts a hop from an unlabelled source at the target a UNIQUE index pins - #12159
Conversation
…urce at the target a UNIQUE index pins - step-based plan: a single fixed-length hop from an unlabelled, unconstrained node to a node pinned on every column of a UNIQUE index (inline map, values may read an UNWIND/WITH row, or WHERE equality/IN over literals and parameters) starts from that node and walks back - unidirectional and untyped hops, OPTIONAL MATCH and path variables keep the written order
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 3 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 62 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
This pull request is merged. |
|
Triage: This looks good. I read the diff only and did not run anything. What it does: In Strengths
Minor suggestions (non-blocking)
I found no security concerns. |
|
Triage: Thanks for the patch. I read the diff and found nothing that blocks a merge. I could not build or run anything, so this is a read-through only. What it does.
Tests. Suggestions, none blocking:
|
…o reads WHERE values of an earlier clause, and keeps the written order when WHERE pins the first node Builds on the contributor's reversal of a single hop from an unlabelled first node to a node a UNIQUE index pins. With main merged in (the cost-based optimizer now plans a plain MATCH of that shape from the labelled node, issue ArcadeData#11904), the step-based plan is the one left for a MATCH after an UNWIND or a WITH, so the tests follow a WITH 1 AS one to stay on it, as the ArcadeData#11904 tests do, and assert the rows read with an anchored pattern instead of a substring that '11 rows' also satisfies. - A WHERE equality or IN-list whose values read a variable an earlier clause bound (UNWIND $keys AS k MATCH (x)-[:OF]->(d:Doc) WHERE d.key = k) reverses the hop too: the issue lists it with the inline map, and the node step seeks the index with the value of the row. - A first node the WHERE clause pins by an equality or IN-list keeps the written order: the node step may seek an index of some type for it, where the walk back from a target with many relationships would read them all. - Tests: a composite key pinned on one column of two, an extra label, a path variable, a variable-length hop, the first node written again as the last, an edge type whose subtype stores no incoming side, several patterns of one MATCH, a predicate on the first node, a CREATE and a DETACH DELETE after the reversed MATCH, keys that are null or of another kind answered as the written order answers them, and a user denied a vertex type, for whom the three plans (this one, the optimizer's, the pattern written from the pinned end) end the same way. The database of the test is dropped before it is created, so a killed run does not fail the class.
|
Triage: Summary: This is a planner-only optimization. In the step-based plan, a single fixed-length hop from an unlabelled, unconstrained source now starts from the target when a UNIQUE index pins every column of the target's label. It reuses the existing What I checked (diff only, nothing was run):
Minor nits (non-blocking):
The PR body reports the same pre-existing failures on main ( |
… reversed plan starts from is not projected by RETURN *
|
Follow-up pushed on top of the contributor's commits (main merged in, no force push):
Tests run on the merged tree: the new class (16), the whole openCypher engine test package without the slow, benchmark and vector lanes (9,722 run, 0 failed), the openCypher TCK suite (3,897 scenarios, 0 failed). |
|
Triage: Thanks for the PR. I read the diff and found no blocking problems. Security: Nothing hazardous. The change only affects query planning ( Correctness
Tests
Nits (non-blocking)
LGTM. |
Fixes #12149.
What changes
In the step-based plan (
CypherExecutionPlan), a pattern of one fixed-length hop now starts from its target when two things hold:WHERE, no id predicate, and is not bound earlier. Starting from it scans every vertex of every type, once per row after anUNWINDorWITH.UNWIND $keys AS k MATCH (x)-[:OF]->(:Doc {key: k})), or from theWHEREclause, as equalities orIN-lists over literals and parameters.The step that starts the pattern then finds the target through that index (per row when the key comes from the row), and the hop walks its relationships backwards. The existing reversal path does this; until now it was reached only for a target already bound by an earlier clause. The pattern keeps its written order for:
Relation to #11904 / #11916: that PR lets the cost-based optimizer take patterns with an unlabelled node when a labelled node has an index seek, which also fixes the two plain
MATCHforms below. The two changes are independent, and when both are merged the optimizer simply takes those statements first. This change covers what reaches the step-based plan regardless, theUNWIND ... MATCH/WITH ... MATCHforms in particular. On the #11916 branch,UNWIND $keys AS k MATCH (x)-[:OF]->(:Doc {key: k})still runsMATCH NODE (x) (400,200 rows).End to end
Graph of the issue at 100k items (100
Docwith a UNIQUEkey, 100,000Item -[:OF]-> Doc, 100,000 unrelatedOther; 200,100 vertices),keys = [7, 8]. Standalone server built from main2eb615cd26. The only difference between the two runs is the engine jar. Median of 5 over HTTP:MATCH (x)-[:OF]->(d:Doc) WHERE d.key IN $keys RETURN labels(x)[0], count(x)MATCH (x)-[:OF]->(d:Doc {key: 7}) RETURN ...UNWIND $keys AS k MATCH (x)-[:OF]->(:Doc {key: k}) RETURN ...MATCH (d:Doc)<-[:OF]-(x) WHERE d.key IN $keys RETURN ...(written fromd, reference)MATCH (x:Item)-[:OF]->(d:Doc) WHERE d.key IN $keys RETURN ...(labelled source, reference)Tests
CypherUnlabelledSourceReverseIssue12149Test(5 tests). Each test asserts, under PROFILE, which node the plan starts from (the firstMATCH NODEstep, its[index: ...]and the rows it read) and checks the answer against the same pattern written from the pinned end. The shapes covered:IN $keys, an inline literal key, a key from anUNWINDrow and from aWITHrow, an incoming arrow, and the cases that keep the written order (NOTUNIQUE key, unidirectional type, untyped hop, OPTIONAL MATCH), with their answers. On main, 4 of the 5 fail. The one that passes is the written-order control.-Dtest='com/arcadedb/query/opencypher/**/*Test' -DexcludedGroups=slow,benchmark,vector): 8,705 run. The only failures areParallelSafeExpressionsStateTest.theWhitelistedExpressionsHoldNoUnsafeMutableStateand 3 errors inCypherCallInTransactionsOnErrorIssue11595Test, which fail the same way on unmodified main2eb615cd26.