Repository navigation
[Bug]: Neo4j performance warnings: Cartesian product in Cypher queries during load testing #906
Description
Describe the bug
During load testing, see #837, the docker logs from the memmachine-app container show repeated Neo4j performance notifications indicating potential inefficiency. The logs report that Cypher queries trigger cartesian product warnings due to disconnected patterns in the MATCH clause, which may cause excessive data generation and slowdowns during query processing.
Steps to reproduce
- Run MemMachine's load test suite or simulate bulk operations involving edge creation in Neo4j.
- Monitor the memmachine-app container logs.
- Observe
[INFO] neo4j.notificationslines with messages about cartesian products, example:Received notification from DBMS server: <GqlStatusObject gql_status='03N90', status_description='info: cartesian product. The disconnected patterns ... build a cartesian product. A cartesian product may produce a large amount of data and slow down query processing.'> for query: 'UNWIND $edges AS edge\nMATCH (source:SANITIZED_Derivative... {uid: edge.source_uid}), (target:SANITIZED_Episode... {uid: edge.target_uid})\nCREATE (source) -[r:SANITIZED_DERIVED_FROM...]-> (target)\nSET r += edge.properties'
Expected behavior
Cypher queries should avoid producing cartesian products unless intended. Queries should match only related node pairs, and logs should not contain unexpected performance warnings. Overall load test performance should not be negatively impacted by inefficient query planning.
Environment
- OS: Linux
- MemMachine Version: (latest under load testing, specify exact version if available)
- Development language version: Python 3.x
- Database: Neo4j (version as configured for docker load tests)
Additional context
Docker logs from the memmachine-app container repeatedly show Neo4j cartesian product performance notifications like:
2026-01-06 22:47:07,920 [INFO] neo4j.notifications - Received notification from DBMS server: <GqlStatusObject gql_status='03N90', status_description='info: cartesian product. The disconnected patterns `(source:SANITIZED_Derivative_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_cc139ee1 {uid: edge.source_uid}), (target:SANITIZED_Episode_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_cc139ee1 {uid: edge.target_uid})` build a cartesian product. A cartesian product may produce a large amount of data and slow down query processing.', ...> for query: 'UNWIND $edges AS edge\nMATCH (source:SANITIZED_Derivative_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_cc139ee1 {uid: edge.source_uid}), (target:SANITIZED_Episode_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_cc139ee1 {uid: edge.target_uid})\nCREATE (source) -[r:SANITIZED_DERIVED_u5f_FROM_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_cc139ee1 {uid: edge.uid}]-> (target)\nSET r += edge.properties'
2026-01-06 22:47:07,921 [INFO] neo4j.notifications - Received notification from DBMS server: <GqlStatusObject gql_status='03N90', status_description='info: cartesian product. The disconnected patterns `(source:SANITIZED_Derivative_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_7e3661c7 {uid: edge.source_uid}), (target:SANITIZED_Episode_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_7e3661c7 {uid: edge.target_uid})` build a cartesian product. A cartesian product may produce a large amount of data and slow down query processing.', ...> for query: 'UNWIND $edges AS edge\nMATCH (source:SANITIZED_Derivative_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_7e3661c7 {uid: edge.source_uid}), (target:SANITIZED_Episode_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_7e3661c7 {uid: edge.target_uid})\nCREATE (source) -[r:SANITIZED_DERIVED_u5f_FROM_u5f_benchmark_u5f_org_u2f_benchmark_u5f_project_u5f_7e3661c7 {uid: edge.uid}]-> (target)\nSET r += edge.properties'
These appear after running bulk/batch ingestion and do not halt operation, but suggest query optimization opportunities.
Activity
sscargal commentedon Jan 7, 2026
Based on my initial analysis, it seems highly likely that the performance warnings (Cartesian product alerts and slowdowns) observed during bulk/batch ingestion in Neo4j are connected to the delayed creation of an index on the uid property. Here’s my hypothesis with known Neo4j and graph database behavior:
Key points:
MATCH (n {uid: ...})) must perform a full scan of all nodes with the label, i.e., anMATCHclauses and disconnected patterns, this leads to full scans for each source/target lookup prior to the CREATE, easily causing cartesian products, excessive data generation, and slow query planning.Effects:
UNWIND+MATCH (source ...), (target ..)pattern produces a cartesian product warning if the two patterns are not connected by a variable in the MATCH. This is worsened if there are no indexes to efficiently look up nodes by uid.Next steps for investigation:
uidonce >10,000 nodes exist.Suggested next steps: