I'm trying to run a query over 582479 genes using the OR operator, after creating index on the properties: symbol, primaryidentifier, secondaryidentifier and name. This the query:
PROFILE
MATCH(g:Gene) WHERE g.symbol="CG11566" OR
g.primaryidentifier="CG11566" OR
g.secondaryidentifier="CG11566" OR
g.name="CG11566"
RETURN g.id, g.primaryidentifier, g.secondaryidentifier, g.symbol, g.name
ORDER BY g.id;
The performance is very poor, the indexes created are not used but only the label scan-> 2912399 total db hits in 3253 ms
Changed the query to use UNION:
PROFILE
MATCH(g:Gene) WHERE g.symbol='CG11566' return g.id
UNION MATCH(g:Gene) WHERE g.primaryidentifier='CG11566' return g.id
UNION MATCH(g:Gene) WHERE g.secondaryidentifier='CG11566' return g.id
UNION MATCH(g:Gene) WHERE g.name='CG11566' return g.id;
indexes have been used -> 8 total db hits in 73 ms. Much better. Any better way to implement the query without using UNION?
There is not much else you can do right now, Cypher's planner would have to get cleverer
The UNION is imho the best solution right now.
neo4j 3.2 has introduced the use of indexes with the OR operator. Great!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With