-
Notifications
You must be signed in to change notification settings - Fork 159
Open
Labels
Description
Describe the bug
OGMModel.create({input: [batch]})
generates a gigantic Cypher query for batch inserts and makes the planner and runtime choke.
Type definitions
If applicable, add your type definitions to help us reproduce the bug.
To Reproduce
Steps to reproduce the behavior:
- Run
OGMModel.create({input: [batch]})
with a batch (~1000 rows) - See the Neo4j instance getting slow and having a 100% CPU utilization
Expected behavior
I expect the creation of a batch with around 1000 rows to be done in milliseconds.
Log
Example neo4j/graphql
debug log with a batch with one item to show the generated query:
Query:
mutation ($input: [PlotCreateInput!]!) {
createPlots(input: $input) {
plots {
id
featureId
title
description
country
cadastralNumber
area
bbox
name
createdAt
updatedAt
}
}
}
Variables:
{
"input": [
{
"id": "AT-91234-1234/2",
"featureId": 59494,
"title": "1234/2",
"description": "GNR 1234/2, KG 91234 SomeString",
"country": "AT",
"cadastralNumber": "91234",
"area": 152271.7361600399,
"bbox": [
9.889720987,
42.232098474,
9.900413672,
47.325398932
],
"name": "",
"project": {
"connect": {
"where": {
"node": {
"id": "1bfb923c-dc6b-4014-b042-2e8ec3f851c8"
}
}
}
}
}
]
} +62ms
@neo4j/graphql:execute About to execute Cypher:
Cypher:
CALL {
CREATE (this0:Plot)
SET this0.createdAt = datetime()
SET this0.updatedAt = datetime()
SET this0.id = $this0_id
SET this0.featureId = $this0_featureId
SET this0.title = $this0_title
SET this0.description = $this0_description
SET this0.country = $this0_country
SET this0.cadastralNumber = $this0_cadastralNumber
SET this0.area = $this0_area
SET this0.bbox = $this0_bbox
SET this0.name = $this0_name
WITH this0
CALL {
WITH this0
OPTIONAL MATCH (this0_project_connect0_node:Project)
WHERE this0_project_connect0_node.id = $this0_project_connect0_node_id
FOREACH(_ IN CASE this0 WHEN NULL THEN [] ELSE [1] END |
FOREACH(_ IN CASE this0_project_connect0_node WHEN NULL THEN [] ELSE [1] END |
MERGE (this0)<-[:BELONGS_TO]-(this0_project_connect0_node)
)
)
RETURN count(*)
}
WITH this0
CALL {
WITH this0
MATCH (this0)<-[this0_project_Project_unique:BELONGS_TO]-(:Project)
WITH count(this0_project_Project_unique) as c
CALL apoc.util.validate(NOT(c <= 1), '@neo4j/graphql/RELATIONSHIP-REQUIREDPlot.project must be less than or equal to one', [0])
RETURN c AS this0_project_Project_unique_ignored
}
RETURN this0
}
RETURN
this0 { .id, .featureId, .title, .description, .country, .cadastralNumber, .area, .bbox, .name, createdAt: apoc.date.convertFormat(toString(this0.createdAt), "iso_zoned_date_time", "iso_offset_date_time"), updatedAt: apoc.date.convertFormat(toString(this0.updatedAt), "iso_zoned_date_time", "iso_offset_date_time") } AS this0
Params:
{
"this0_id": "AT-91234-1234/2",
"this0_featureId": {
"low": 59494,
"high": 0
},
"this0_title": "1234/2",
"this0_description": "GNR 1234/2, KG 91234 SomeString",
"this0_country": "AT",
"this0_cadastralNumber": "91234",
"this0_area": 152271.7361600399,
"this0_bbox": [
9.889720987,
42.232098474,
9.900413672,
47.325398932
],
"this0_name": "",
"this0_project_connect0_node_id": "1bfb923c-dc6b-4014-b042-2e8ec3f851c8"
} +4ms
@neo4j/graphql:execute Execute successful, received 1 records +182ms
System (please complete the following information):
- OS: MacOS
- Version:
"@neo4j/graphql": "^3.0.3",
"@neo4j/graphql-ogm": "^3.0.3",
- Node.js version: v16.14.0
- Neo4j instance: Neo4j instance in AuraDB (1GB RAM, 1 CPU, 2GB Storage - the smallest version)
raulsteurer, tobsut97 and rschiffer