Hi,
We have a redisgraph db with nodes and relations in order of 100 millions. We are running a query of the following form
GRAPH.query test "match (a:L1{id=123}) -[r1:REL1]-> (b:L1) -[r2:REL2]-> (c:L2) where c.prop1='val1' return c.prop, ..."
the execution plan of this query shows that it first Index scans a:L1 and then traverses to b:L1 and c:L2 via REL1 and REL2. However when we are adding an additional filter condition as follows
GRAPH.query test "match (a:L1{id=123}) -[r1:REL1]-> (b:L1) -[r2:REL2]-> (c:L2) where c.prop1='val1' and c.prop2='val2' return c.prop, ..."
then the direction of traversal in execution plan reverses to: index scan c:L2 then traverse to b:L1 then traverse to a:L1.
There are exact match indexes on prop1 and prop2 for L2, as well as id field for L1, however, the filter id=123 identifies a single L1 node here but prop1=val1 and prop2=val2 could match with a huge number of L2 nodes. So with the scanning order reversed, the second query is taking a lot of time and times out even after 60 seconds.
Could someone help suggest what should we do so that the scanning happens as the one in first query with single filter condition in where clause? Or any alternatives. Thanks in advance.
Small example to see the query execution plan change:
graph creation
graph.query test "CREATE
(kavish:Author {name: 'Kavish', email:'kavish@contact.com'}),
(book1:Book {name: 'book1', isbn: '1'}),
(kavish)-[:WROTE{year:2001}]->(book1)"
graph.query test "create index for (q:Book) on (q.name)"
graph.query test "create index for (q:Book) on (q.isbn)"
graph.query test "create index for (q:Author) on (q.name)"
query with only one condition in where clause (traversal ordering is as mentioned in cypher)
GRAPH.EXPLAIN test "match (a:Author{name:'kavish'}) -[WROTE]-> (b:Book) where b.name='book1' return b.name"
1) "Results"
2) " Project"
3) " Filter"
4) " Conditional Traverse | (a)->(b:Book)"
5) " Node By Index Scan | (a:Author)"
query with two condition in where clause (traversal ordering reversed)
GRAPH.EXPLAIN test "match (a:Author{name:'kavish'}) -[WROTE]-> (b:Book) where b.name='book1' and b.isbn='1' return b.name"
1) "Results"
2) " Project"
3) " Filter"
4) " Conditional Traverse | (b)->(a:Author)"
5) " Node By Index Scan | (b:Book)"