Unexpected optimization when using ORs


Brad Peters <br...@...>
 

I have a traversal like this

g.V()
  .and( 
    __.or(
      __.has("field1",P.within(["value1"])),
      __.has("field2",P.eq((int) 0))
    )
  ,
    .has("field3",P.within(["value3"]))
    .has("field4",P.eq(true))
    .or(
      __.has("field5",textRegex(".*value5")),
      __.has("field6",textRegex(".*value6"))
    )
  )

with a mixed index (ES) that covers all 6 fields, I would expect that to return vertices that matched either field 1 or 2 and fields 3 and 4 and either of field 5 or 6 but what I get is a profile that creates an index query that looks like this

(
  (field3 = value3 AND field4 = true AND field1 = value1) 
  OR 
  (field3 = value3 AND field4 = true AND field2 = 0) 
  OR 
  (field3 = value3 AND field4 = true AND field5 textRegex .*value5)
  OR 
  (field3 = value3 AND field4 = true AND field6 textRegex .*value6)
)

I have dug through the strategy code and I see how the ANDs and ORs get reordered and then folded to result in this query, what I am asking is there a way I can write this traversal that will accomplish what I want without having to add support to JanusGraph itself?