cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Count() is returning wrong value for total nodes with a label

I believe this might be some configuration problem, as it was giving the correct count a few days ago.

E.g

neo4j> match (n:LabelA) return n limit 35;
+------------------------------------------------------------------+
| n                                                                |
+------------------------------------------------------------------+
| (:LabelA {score: 0.9737793851717902, id: "A"})   |
| (:LabelA {score: 0.9737793851717902, id: "B"})   |
| (:LabelA {score: 0.9746835443037974, id: "C"})    |
| (:LabelA {score: 0.9746835443037974, id: "D"})   |
| (:LabelA {score: 0.9746835443037974, id: "E"})   |
| (:LabelA {score: 0.009041591320072333, id: "F"}) |
| (:LabelA {score: 0.0108499095840868, id: "G"})   |
| (:LabelA {score: 0.0108499095840868, id: "H"})   |
| (:LabelA {score: 0.01175406871609403, id: "I"})  |
| (:LabelA {score: 0.01175406871609403, id: "J"})  |
| (:LabelA {score: 0.0135623869801085, id: "K"})   |
| (:LabelA {score: 0.0135623869801085, id: "L"})   |
| (:LabelA {score: 0.01446654611211573, id: "M"})  |
| (:LabelA {score: 0.01446654611211573, id: "N"})  |
| (:LabelA {score: 0.01537070524412297, id: "O"})  |
| (:LabelA {score: 0.01808318264014467, id: "P"})  |
| (:LabelA {score: 0.01989150090415913, id: "Q"})  |
| (:LabelA {score: 0.02260397830018083, id: "R"})  |
| (:LabelA {score: 0.02350813743218806, id: "S"})  |
| (:LabelA {score: 0.02350813743218806, id: "T"})  |
| (:LabelA {score: 0.0244122965641953, id: "U"})   |
| (:LabelA {score: 0.02622061482820976, id: "V"})  |
| (:LabelA {score: 0.027124773960217, id: "W"})    |
| (:LabelA {score: 0.027124773960217, id: "X"})    |
| (:LabelA {score: 0.0298372513562387, id: "Y"})   |
| (:LabelA {score: 0.03074141048824593, id: "Z"})   |
| (:LabelA {score: 0.03074141048824593, id: "AA"})  |
| (:LabelA {score: 0.0325497287522604, id: "BB"}) |
| (:LabelA {score: 0.0325497287522604, id: "CC"})   |
| (:LabelA {score: 0.03978300180831826, id: "DD"})  |
| (:LabelA {score: 0.0406871609403255, id: "EE"})   |
| (:LabelA {score: 0.0433996383363472, id: "FF"})   |
| (:LabelA {score: 0.0433996383363472, id: "GG"})   |
| (:LabelA {score: 0.04430379746835443, id: "HH"})  |
| (:LabelA {score: 0.04520795660036166, id: "II"})  |
+------------------------------------------------------------------+

35 rows available after 1 ms, consumed after another 1 ms
neo4j> match (n:LabelA) return count(n);
+----------+
| count(n) |
+----------+
| 31       |
+----------+

1 row available after 1 ms, consumed after another 0 ms

There are supposed to be 3968 total nodes, but it returns 31. If I delete all the nodes, then it shows the correct number of nodes deleted.

neo4j> match (n:LabelA) detach delete(n);
0 rows available after 132 ms, consumed after another 0 ms
Deleted 3968 nodes, Deleted 7452 relationships
1 ACCEPTED SOLUTION

I think there is an issue with count store. When you run the query

match (n:LabelA) return count(n);

It uses the count stores to return the data quickly. It actually does not count the nodes. In few scenarios the count stores may not have gotten updated properly.

Best way to recover is to follow these steps.

  1. Stop DB
  2. delete neostore.counts.db.*
  3. start DB

That should recreate the count stores properly.

View solution in original post

4 REPLIES 4

yyyguy
Graph Buddy

Hello,

I notice that in your first query, you have a LIMIT statement. With the limit of 35, the query will return at most 35 nodes.

-yyyguy

Hi, the limit was to show there are more than 31, which is what the count query is returning. Edit: the count query is below the query with the limit, you have to scroll down to see it

I think there is an issue with count store. When you run the query

match (n:LabelA) return count(n);

It uses the count stores to return the data quickly. It actually does not count the nodes. In few scenarios the count stores may not have gotten updated properly.

Best way to recover is to follow these steps.

  1. Stop DB
  2. delete neostore.counts.db.*
  3. start DB

That should recreate the count stores properly.

Do you know by chance if this will get addressed/fixed?