Skip to content

When querying only for totalCount within a *Connection query, the generated cypher queries and returns too much data resulting in serious performance-issues #6115

@andreloeffelmann

Description

@andreloeffelmann

Describe the bug
When querying only for totalCount within a *Connection query, database-internal data is returned for each found node-instance resulting in a HUGE response. This totally kills the performance when having many nodes.
See the steps to reproduce. When running this query on our production database with Neo4j Desktop, the app completely dies and shuts down. And we only have around 2m nodes of this type. We have other types with ~80m nodes. Don't want to know what would happen if I executed this query on that type...

Type definitions

type Norm {
  code: String!
}

To Reproduce

  1. Run a server with the type defs
  2. Execute the following Query:
query {
  normsConnection {
    totalCount
  }
}
  1. The following cypher is generated
MATCH (this0:Norm)
WITH collect({ node: this0 }) AS edges
WITH edges, size(edges) AS totalCount
CALL {
  WITH edges
  UNWIND edges AS edge
  WITH edge.node AS this0
  RETURN collect({ node: { __id: id(this0), __resolveType: "Norm" } }) AS var1
}
RETURN { edges: var1, totalCount: totalCount } AS this
  1. This results in a response with the following structure:
{
  "edges": [
    {
      "node": {
        "__resolveType": "Norm",
        "__id": 42942
      }
    },
    {
      "node": {
        "__resolveType": "Norm",
        "__id": 47617
      }
    },
  ....
  ],
  "totalCount": 185
}
  1. The sub-object node with the keys __resolveType and __id is returned for EACH found instance.

Expected behavior
When querying on a connection including only totalCount, the irrelevant meta-information should NOT be returned to keep perfomance.
Even to query for is a perfomance killer, I think.
A simple cypher to aim for the count-store only should be sufficient:

MATCH (this0:Norm)
RETURN {totalCount:count(this0)}

System

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions