Hi Boxuan,
I put an example of a query we try to make working with indexes at the end of the message, it is a test case I wrote in the QueryTest.java file.
> It does not work in the way you presume.
from GraphCentricQueryBuilder.java:261
indexType -> indexType.getElement() == resultType && !(conditions instanceof Or && (indexType.isCompositeIndex() || !serializer.features((MixedIndexType) indexType).supportNotQueryNormalForm()))));
Maybe I am just stupid and I don't see it, but the conditions instanceof Or would is always true (if the toplevel query is an Or, which is the case for our queries) and we only have compositeIndex, so the indexType would never be picked in the indexCandidates Set, right ?
Therefore all indexType would be filtered out of the collection and no index would be used for the query.
And we are using JanusGraph 0.5.2 (and impatient to go with the 0.6 :) ! )
Thx for your time and best wishes !
Sylvain
--------------------
@Test
public void testTopLevelOrUseIndexesForSubQuery() {
JanusGraphManagement mgmt = graph.openManagement();
PropertyKey prop1Key = mgmt.makePropertyKey("prop1").dataType(String.class).make();
PropertyKey prop2Key = mgmt.makePropertyKey("prop2").dataType(String.class).make();
mgmt.buildIndex("prop1_idx", Vertex.class).addKey(prop1Key).buildCompositeIndex();
mgmt.buildIndex("prop2_idx", Vertex.class).addKey(prop2Key).buildCompositeIndex();
mgmt.commit();
for (int i = 0; i < 20; i++) {
tx.addVertex("file").property("prop1", "p1_" + i).element().property("prop2", "p2_" + i);
}
GraphCentricQueryBuilder andQueryBuilder = (GraphCentricQueryBuilder) tx.query();
andQueryBuilder.has("prop1", "p1_9").has("~label", "file");
// this is good, andQuery.indexQuery.backendQuery.queries contain one JointIndexQuery and use the prop1_idx:multiKSQ[1]@2005 index
GraphCentricQuery andQuery = andQueryBuilder.constructQuery(ElementCategory.VERTEX);
Iterable<JanusGraphVertex> resultAnd = andQueryBuilder.vertices();
GraphCentricQueryBuilder orQueryBuilder = (GraphCentricQueryBuilder) tx.query();
GraphCentricQueryBuilder subQuery1 = (GraphCentricQueryBuilder) tx.query();
GraphCentricQueryBuilder subQuery2 = (GraphCentricQueryBuilder) tx.query();
subQuery1.has("prop1", "p1_9").has("~label", "file");
subQuery2.has("prop2", "p2_9").has("~label", "file");
orQueryBuilder.or(subQuery1).or(subQuery2);
// this is good, andQuery.indexQuery.backendQuery.queries contain nothing
GraphCentricQuery orQuery = orQueryBuilder.constructQuery(ElementCategory.VERTEX);
Iterable<JanusGraphVertex> resultOr = orQueryBuilder.vertices();
}