JanusGraph / JanusGraph/janusgraph

Improve AdjacentVertexHasIdOptimizerStrategy

Open
#2,842 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
5.8k
Forks
1.2k
Avg merge
13h 53m
Merged PRs (30d)
6

Description

Currently AdjacentVertexHasIdOptimizerStrategy does not support hasContainers with more than 1 step

So next traversal not optimized

```
graph.traversal().V().hasId(P.within(1L)).bothE().otherV().hasId(2L).has('a','b').explain()
```
```
AdjacentVertexHasIdOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), HasStep([~id.eq(2), a.eq(b)])]
AdjacentVertexFilterOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), HasStep([~id.eq(2), a.eq(b)])]
AdjacentVertexIsOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), HasStep([~id.eq(2), a.eq(b)])]
```

It cat be rewritten like this to utilize optimization

```
graph.traversal().V().hasId(P.within(1L)).bothE().otherV().is(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex.build().setId(2L).create()).has('w','w').explain()
```

```
AdjacentVertexHasUniquePropertyOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), IsStep(eq(v[2])), HasStep([w.eq(w)])]
AdjacentVertexHasIdOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,vertex), IsStep(eq(v[2])), HasStep([w.eq(w)])]
AdjacentVertexIsOptimizerStrategy [P] [GraphStep(vertex,[]), HasStep([~id.within([1])]), VertexStep(BOTH,edge), HasStep([~adjacent.eq(v[2])]), EdgeOtherVertexStep, HasStep([w.eq(w)])]
```

For simple cases AdjacentVertexHasIdOptimizerStrategy may extract hasId step from hasContainer

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AdjacentVertexHasIdOptimizerStrategy and compare the two explain() examples in the issue. Verify that the multi-step hasContainer traversal is rewritten to the intended IsStep form, while simple hasId cases continue to optimize.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.