Index on subquery not working


Veerle <vvanbe...@...>
 

Hi,

I do have a graph with about 1 million vertexes and a many to many relation between those vertexes.
The vertexes are 

I created a mixed index 

management.buildIndex(indexName, Vertex.class)
                .addKey(management.getPropertyKey("property"))
                .indexOnly(road)
                .buildMixedIndex("search"); 

The index is working correctly, I can see it popping up in the profile output:
graph
.V()
.hasLabel(
"road")
.has("property", true)
.profile().next()

But when I want to have the same on the other side of the "connected" relation, the index is not used anymore.
graph
.V().both("connected")
.hasLabel("road")
.has("property", true)
        .profile().next()
Does someone know how I get the subquery to use the index?

Thanks a lot, Veerle


BO XUAN LI <libo...@...>
 

Hi Veerle,

Try putting both(“connected”) after has(“property”, true).

Regards,
Boxuan

On Aug 10, 2020, at 8:10 PM, Veerle <vvanbe...@...> wrote:

Hi,

I do have a graph with about 1 million vertexes and a many to many relation between those vertexes.
The vertexes are 

I created a mixed index 

management.buildIndex(indexName, Vertex.class)
                .addKey(management.getPropertyKey("property"))
                .indexOnly(road)
                .buildMixedIndex("search"); 

The index is working correctly, I can see it popping up in the profile output:
graph
.V()
.hasLabel(
"road")
.has("property", true)
.profile().next()

But when I want to have the same on the other side of the "connected" relation, the index is not used anymore.
graph
.V().both("connected")
.hasLabel("road")
.has("property", true)
        .profile().next()
Does someone know how I get the subquery to use the index?

Thanks a lot, Veerle

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgra...@....
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/a9e313d7-cffa-442a-b2ca-f20339767103o%40googlegroups.com.


Veerle <vvanbe...@...>
 

Thanks for the answer but putting  has(“property”, true) before both(“connected”) changes the results of the query.

I actually simplefied my query a bit for my question here but what I want is a query that selects all relations where on one side the property is true and on the other side the property is false.
Something like this:

V()
        .hasLabel("road")
        .has("property", true)
        .both("connected")
        .hasLabel("road")
        .has("property", false)
.next()

The first part of the query uses the index, but the second part isn't.

Thanks, Veerle


BO XUAN LI <libo...@...>
 

That’s pretty much expected. Index is used when you have a global lookup. In your case, the first has("property", true) is a global lookup, so it leverages index. The second has("property", true) is to check neighbors, or in other words, a local lookup, so it does not use index.

Depending on your data, there are a couple of things you can try:

1) You can build an index for edges, which indicates whether two endpoints have opposite properties.

2) You can use different edge labels to indicate different cases. Try with and without vertex-centric indexes.

3) Retrieve all vertices with property=true and all with property=false, do in-memory filtering in your application.

Hope this helps.

On Aug 10, 2020, at 11:18 PM, Veerle <vvanbe...@...> wrote:

Thanks for the answer but putting  has(“property”, true) before both(“connected”) changes the results of the query.

I actually simplefied my query a bit for my question here but what I want is a query that selects all relations where on one side the property is true and on the other side the property is false.
Something like this:

V()
        .hasLabel("road")
        .has("property", true)
        .both("connected")
        .hasLabel("road")
        .has("property", false)
.next()

The first part of the query uses the index, but the second part isn't.

Thanks, Veerle


--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgra...@....
To view this discussion on the web visit https://groups.google.com/d/msgid/janusgraph-users/407b9e9b-6d32-4bb6-ba1d-7eb1f8202265o%40googlegroups.com.