Andreas Schouten
Andreas Schouten

Reputation: 53

Performance issue with two full-text calls in one cypher query

I need to combine results of two full-text calls. Both returns separate within few seconds, but takes together minutes.

I removed all MATCH and other clauses to isolate the problem best.

If I call

CALL db.index.fulltext.queryNodes("nameIndex", 'some word') YIELD node as kw
RETURN count(kw)

or

CALL db.index.fulltext.queryNodes("article_fulltext", 'other word') YIELD node as a 
RETURN count(a)

both return in less than a second and shows about 500.000

But if I call


CALL db.index.fulltext.queryNodes("nameIndex", 'some word') YIELD node as kw
CALL db.index.fulltext.queryNodes("article_fulltext", 'other word') YIELD node
RETURN count(a), count(kw)

It takes minutes.

I tried to separate if but without an effect.

CALL db.index.fulltext.queryNodes("nameIndex", 'some word') YIELD node as kw
WITH kw , count(kw) as kwl
WITH kwl
CALL db.index.fulltext.queryNodes("article_fulltext", 'other word') YIELD node as a 
WITH kwl, a ,count(a) as al
RETURN kwl, al

How to tell neo4j that this calls are independent?

Upvotes: 1

Views: 190

Answers (1)

cybersam
cybersam

Reputation: 67044

Since your first CALL returns 500K results, your second CALL is invoked 500K times. That is obviously not what you intended and very, very slow. And it and would also give you the wrong counts.

Use WITH COUNT() to reduce the number of results from the first CALL to just one.

For example, this should be much faster and also give you the correct counts:

CALL db.index.fulltext.queryNodes("nameIndex", 'some word') YIELD node
WITH COUNT(node) AS kws
CALL db.index.fulltext.queryNodes("article_fulltext", 'other word') YIELD node
RETURN COUNT(node) AS ows, kws

Upvotes: 3

Related Questions