Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad performance with OR operator

Tags:

neo4j

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?

like image 280
Daniela Butano Avatar asked May 24 '16 15:05

Daniela Butano


2 Answers

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.

like image 90
Michael Hunger Avatar answered Oct 06 '22 07:10

Michael Hunger


neo4j 3.2 has introduced the use of indexes with the OR operator. Great!

like image 21
Daniela Butano Avatar answered Oct 06 '22 07:10

Daniela Butano