Poor work with the OR operator

I try to run a query on genes 582479 using the OR operator after creating an index of properties: symbol, primaryidentifier, secondaryidentifier and name. This request:

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; 

Performance is very low, created indexes are not used, but only label scan → 2912399 total number of deleted elements in 3253 ms

Request to use UNION has been changed:

 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 Used

-> 8 total db deletes in 73 ms. Much better. Any better way to implement a query without using UNION?

+6
source share
3 answers

Not much that you can do right now, the Cypher planner will have to be smarter

UNION is the best solution at the moment.

+2
source

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

+1
source

You can split the query into 4 parts (one for each condition) and collect all the results in one array, which is unwound in the last step:

 MATCH (g1:Gene{symbol:'CG11566'}) WITH collect(g1) as c1 MATCH (g2:Gene{primaryidentifier:'CG11566'}) WITH c1 + collect(g2) as c2 MATCH (g3:Gene{secondaryidentifier:'CG11566'}) WITH c2 + collect(g3) as c3 MATCH (g4:Gene{name:'CG11566'}) WITH c3 + collect(g4) as c4 UNWIND c4 as gene ... do stuff with genes found by any of the 4 parts 
0
source

All Articles