I found the following interesting behaviour today wenn running some basic statistics on my dataset.
What the relevant part of the dataset looks like:
there are multiple nodes for each of the labels :LABEL1 :LABEL2 :LABEL3
What I did:
MATCH (p:LABEL1), (pr:LABEL2), (fp:LABEL3) RETURN COUNT(pr), COUNT(p), COUNT(fp)
What I expected as a result: getting amount of nodes for the respective labels:
- count(pr): 12
- count(p): 206
- count(fp): 126
The actual result: all 3 showed the same number as count (
311472) (that's the product of the three expected results by the way^^)
Now that was some interesting result.
I tried again with separating the queries into single matches connected with
MATCH (p:LABEL1) WITH p MATCH(pr:LABEL2) WITH p, pr MATCH (fp:LABEL3) RETURN count(pr), count(p), count(fp)
The result stayed the same.
I tried again with counting each of the variables before matching the next one and now got the result I'd expect.
match(p:LABEL1) with count(p) as pcount match (pr:LABEL2) with pcount, count(pr) as prcount match (fp:LABEL3) RETURN count(fp), pcount, prcount
It's of course possible, that 311472 is just the correct result for the query I posted and that I don't understand well enough how the count() function works.
In that case I'd be very happy if someone explains to me where my line of thinking is flawed. In case it's a real bug and you're able to reproduce it I'm happy to have been of help
neo4j Desktop, database version: 4.1.4