JanusGraph / JanusGraph/janusgraph

Wrong result for count query when mixed index optimization used

Open
#3,059 5 comments 0 reactions 0 assignees View on GitHub
area/core kind/bug/possible
Dominant language
Java
Stars
5.8k
Forks
1.2k
Avg merge
13h 53m
Merged PRs (30d)
6

Description

For confirmed bugs, please report:
- Version: 0.6.0
- Storage Backend: all
- Mixed Index Backend: all
- Link to discussed bug:
- Expected Behavior: correct answer
- Current Behavior: in tx element not affected in count
- Steps to Reproduce:

```
gremlin> graph = JanusGraphFactory.build().
......1> set("storage.backend","berkeleyje").
......2> set("storage.directory","/tmp/graph").
......3> set("index.search.backend","lucene").
......4> set("index.search.directory","/tmp/graph/").
......5> open()
==>standardjanusgraph[berkeleyje:/tmp/graph]
gremlin> g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[berkeleyje:/tmp/graph], standard]
gremlin>
gremlin> mgmt = graph.openManagement()
==>org.janusgraph.graphdb.database.management.ManagementSystem@2506e949
gremlin> p1 = mgmt.makePropertyKey('p1').cardinality(Cardinality.SINGLE).dataType(String.class).make()
==>p1
gremlin> mgmt.buildIndex("string", Vertex.class).addKey(p1, Mapping.STRING.asParameter()).buildMixedIndex("search")
==>string
gremlin> mgmt.commit()
==>null
gremlin> graph.traversal().addV().property("p1","v")
==>v[4256]
gremlin> graph.tx().commit()
==>null
gremlin> graph.traversal().V().has("p1").count().profile()
==>Traversal Metrics
Step Count Traversers Time (ms) % Dur
=============================================================================================================
JanusGraphMixedIndexCountStep 1 1 59.540 100.00
MixedIndexCountQuery 58.041
\_query=[(p1 <> null)]:string
>TOTAL - - 59.540 -
gremlin> graph.traversal().V().has("p1").count()
==>1
gremlin> graph.traversal().addV().property("p1","v2")
==>v[4168]
gremlin> graph.traversal().V().has("p1").count()
==>1 <---- Wrong
gremlin> graph.traversal().withoutStrategies(org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMixedIndexCountStrategy.class).V().has("p1").count()
==>2 <---- Correct
gremlin> graph.traversal().withoutStrategies(org.janusgraph.graphdb.tinkerpop.optimize.strategy.JanusGraphMixedIndexCountStrategy.class).V().has("p1").count().profile()
==>Traversal Metrics
Step Count Traversers Time (ms) % Dur
=============================================================================================================
JanusGraphStep([],[p1.neq]) 2 2 1.232 88.01
constructGraphCentricQuery 0.238
GraphCentricQuery 0.753
\_condition=(p1 <> null)
\_orders=[]
\_isFitted=true
\_isOrdered=true
\_query=[(p1 <> null)]:string
\_index=string
\_index_impl=search
CountGlobalStep 1 1 0.167 11.99
>TOTAL - - 1.400 -
gremlin>

```

Contributor guide

Open the contributing guide

Research direction

Start with the JanusGraphMixedIndexCountStrategy and the profiled mixed-index count query shown in the reproduction. Run the Gremlin sequence with and without that strategy, then inspect how the transaction's newly added element is handled. Done means the optimized count returns 2, matching the non-optimized traversal.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.