- neo4j version, desktop version, browser version : 4.4.35
- what kind of API / driver do you use : neo4j-java-driver (4.4.12)
Following is a relationship based Cypher query executed to extract data at each relationship level. When are executing this Cypher directly via the Neo4j browser. Query is executed to get data at different Node level (Order -> Order -> Organization -> Catalog<3 levels> ) and we extract data from each level for our reporting. When Neo4j runs this cypher which is multi level based the query takes around 25secs to 30secs to get a response. But if we reduced the relationship to Order -> Order -> Organization -> Catalog <1 level>, then the query returns within 8secs. I am confused whether this a Cypher query problem (or) are there any performance improvements which can be done for this cypher query execution to speed up the response time. Any kind of inputs to improve the cypher execution is highly appreciated. Thanks in advance
Note: I have also attached the explain plan for analysis.
MATCH (orderline:`OrderLine` {
tenantId: '853357c4-28f3-4f69-b95a-7ee38363e798', type: 'OrderLine'
})
WITH orderline SKIP 0
LIMIT 51 CALL {
WITH orderline
MATCH (orderline)-[:`RELATES_TO` {fieldName: 'order'
}]->(order:`Order` {
tenantId: '853357c4-28f3-4f69-b95a-7ee38363e798'
})
WITH order CALL {
WITH order
MATCH (order)-[:`RELATES_TO` {fieldName: 'buyer'
}]->(organization:`Organization` {
tenantId: '853357c4-28f3-4f69-b95a-7ee38363e798'
})
WITH organization CALL {
WITH organization
MATCH (organization)-[:`RELATES_TO` {fieldName: 'category1'
}]->(catalog:`Catalog` {
tenantId: '853357c4-28f3-4f69-b95a-7ee38363e798'
})
WITH catalog
WITH collect(catalog{.*, _id: id(catalog)})[0..6] AS collectionAlias, count(catalog) AS countAlias
RETURN {
dataList: collectionAlias, totalCount: countAlias
} AS Organization_Catalog_category1__info} CALL {
WITH organization
MATCH (organization)-[:`RELATES_TO` {fieldName: 'category2'
}]->(catalog:`Catalog` {
tenantId: '853357c4-28f3-4f69-b95a-7ee38363e798'
})
WITH catalog
WITH collect(catalog{.*, _id: id(catalog)})[0..6] AS collectionAlias, count(catalog) AS countAlias
RETURN {
dataList: collectionAlias, totalCount: countAlias
} AS Organization_Catalog_category2__info} CALL {
WITH organization
MATCH (organization)-[:`RELATES_TO` {fieldName: 'category3'
}]->(catalog:`Catalog` {
tenantId: '853357c4-28f3-4f69-b95a-7ee38363e798'
})
WITH catalog
WITH collect(catalog{.*, _id: id(catalog)})[0..6] AS collectionAlias, count(catalog) AS countAlias
RETURN {
dataList: collectionAlias, totalCount: countAlias
} AS Organization_Catalog_category3__info}
WITH collect(organization{.*, _id: id(organization), category1: Organization_Catalog_category1__info, category2: Organization_Catalog_category2__info, category3: Organization_Catalog_category3__info})[0..6] AS collectionAlias, count(organization) AS countAlias
RETURN {
dataList: collectionAlias, totalCount: countAlias
} AS Order_Organization_buyer__info}
WITH collect(order{.*, _id: id(order), buyer: Order_Organization_buyer__info})[0..6] AS collectionAlias, count(order) AS countAlias
RETURN {
dataList: collectionAlias, totalCount: countAlias
} AS OrderLine_Order_order__info}
RETURN orderline{.*, _id: id(orderline), order: OrderLine_Order_order__info}
- screenshot of
PROFILE
orEXPLAIN
with boxes expanded (lower right corner)
{
"results": [
{
"columns": [
"orderline"
],
"data": [],
"plan": {
"root": {
"operatorType": "ProduceResults@neo4j",
"planner-impl": "IDP",
"Details": "orderline",
"planner-version": "4.4",
"runtime-version": "4.4",
"runtime": "INTERPRETED",
"runtime-impl": "INTERPRETED",
"version": "CYPHER 4.4",
"EstimatedRows": 51,
"planner": "COST",
"identifiers": [
"orderline",
"countAlias",
"OrderLine_Order_order__info",
"anon_28",
"collectionAlias",
"anon_29"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "orderline{_id: id(orderline), order: OrderLine_Order_order__info, .*} AS orderline",
"EstimatedRows": 51,
"identifiers": [
"orderline",
"countAlias",
"OrderLine_Order_order__info",
"anon_28",
"collectionAlias",
"anon_29"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "{dataList: collectionAlias, totalCount: countAlias} AS OrderLine_Order_order__info",
"EstimatedRows": 51,
"identifiers": [
"orderline",
"countAlias",
"OrderLine_Order_order__info",
"anon_28",
"collectionAlias",
"anon_29"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "anon_29[0..6] AS collectionAlias, anon_28 AS countAlias",
"EstimatedRows": 51,
"identifiers": [
"orderline",
"countAlias",
"anon_28",
"collectionAlias",
"anon_29"
],
"children": [
{
"operatorType": "Apply@neo4j",
"EstimatedRows": 51,
"identifiers": [
"orderline",
"anon_28",
"anon_29"
],
"children": [
{
"operatorType": "Skip@neo4j",
"Details": "$autoint_2",
"EstimatedRows": 51,
"identifiers": [
"orderline"
],
"children": [
{
"operatorType": "Limit@neo4j",
"Details": "51 + $autoint_2",
"EstimatedRows": 52,
"identifiers": [
"orderline"
],
"children": [
{
"operatorType": "NodeIndexSeek@neo4j",
"Details": "BTREE INDEX orderline:OrderLine(tenantId, type) WHERE tenantId = $autostring_0 AND type = $autostring_1",
"EstimatedRows": 52.00000000000001,
"identifiers": [
"orderline"
],
"children": []
}
]
}
]
},
{
"operatorType": "EagerAggregation@neo4j",
"Details": "count(order) AS anon_28, collect(order{_id: id(order), buyer: Order_Organization_buyer__info, .*}) AS anon_29",
"EstimatedRows": 51,
"identifiers": [
"anon_28",
"anon_29"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "{dataList: collectionAlias, totalCount: countAlias} AS Order_Organization_buyer__info",
"EstimatedRows": 0.051043379947513935,
"identifiers": [
"orderline",
"countAlias",
"anon_0",
"anon_26",
"collectionAlias",
"anon_27",
"Order_Organization_buyer__info",
"order"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "anon_27[0..6] AS collectionAlias, anon_26 AS countAlias",
"EstimatedRows": 0.051043379947513935,
"identifiers": [
"orderline",
"countAlias",
"anon_0",
"anon_26",
"collectionAlias",
"anon_27",
"order"
],
"children": [
{
"operatorType": "Apply@neo4j",
"EstimatedRows": 0.051043379947513935,
"identifiers": [
"orderline",
"anon_0",
"anon_26",
"anon_27",
"order"
],
"children": [
{
"operatorType": "Filter@neo4j",
"Details": "order:Order AND anon_0.fieldName = \"order\" AND order.tenantId = \"853357c4-28f3-4f69-b95a-7ee38363e798\"",
"EstimatedRows": 0.051043379947513935,
"identifiers": [
"orderline",
"anon_0",
"order"
],
"children": [
{
"operatorType": "Expand(All)@neo4j",
"Details": "(orderline)-[anon_0:RELATES_TO]->(order)",
"EstimatedRows": 208.5736852658071,
"identifiers": [
"orderline",
"anon_0",
"order"
],
"children": [
{
"operatorType": "Argument@neo4j",
"Details": "orderline",
"EstimatedRows": 51,
"identifiers": [
"orderline"
],
"children": []
}
]
}
]
},
{
"operatorType": "EagerAggregation@neo4j",
"Details": "count(organization) AS anon_26, collect(organization{_id: id(organization), category1: Organization_Catalog_category1__info, category2: Organization_Catalog_category2__info, category3: Organization_Catalog_category3__info, .*}) AS anon_27",
"EstimatedRows": 0.051043379947513935,
"identifiers": [
"anon_26",
"anon_27"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "{dataList: collectionAlias, totalCount: countAlias} AS Organization_Catalog_category3__info",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"countAlias",
"Organization_Catalog_category2__info",
"anon_20",
"Organization_Catalog_category3__info",
"anon_22",
"anon_21",
"anon_24",
"anon_23",
"anon_1",
"organization",
"anon_25",
"collectionAlias",
"Organization_Catalog_category1__info",
"order"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "anon_25[0..6] AS collectionAlias, anon_24 AS countAlias",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"countAlias",
"Organization_Catalog_category2__info",
"anon_20",
"anon_22",
"anon_21",
"anon_24",
"anon_23",
"anon_1",
"organization",
"anon_25",
"collectionAlias",
"Organization_Catalog_category1__info",
"order"
],
"children": [
{
"operatorType": "Apply@neo4j",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"countAlias",
"Organization_Catalog_category2__info",
"anon_20",
"anon_22",
"anon_21",
"anon_24",
"anon_23",
"anon_1",
"organization",
"anon_25",
"collectionAlias",
"Organization_Catalog_category1__info",
"order"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "{dataList: collectionAlias, totalCount: countAlias} AS Organization_Catalog_category2__info",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_20",
"anon_22",
"countAlias",
"anon_21",
"anon_23",
"anon_1",
"organization",
"collectionAlias",
"Organization_Catalog_category2__info",
"Organization_Catalog_category1__info",
"order"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "anon_23[0..6] AS collectionAlias, anon_22 AS countAlias",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_20",
"anon_22",
"countAlias",
"anon_21",
"anon_23",
"anon_1",
"organization",
"collectionAlias",
"Organization_Catalog_category1__info",
"order"
],
"children": [
{
"operatorType": "Apply@neo4j",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_20",
"anon_22",
"countAlias",
"anon_21",
"anon_23",
"anon_1",
"organization",
"collectionAlias",
"Organization_Catalog_category1__info",
"order"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "{dataList: collectionAlias, totalCount: countAlias} AS Organization_Catalog_category1__info",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_20",
"countAlias",
"anon_21",
"anon_1",
"organization",
"collectionAlias",
"Organization_Catalog_category1__info",
"order"
],
"children": [
{
"operatorType": "Projection@neo4j",
"Details": "anon_21[0..6] AS collectionAlias, anon_20 AS countAlias",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_20",
"countAlias",
"anon_21",
"anon_1",
"organization",
"collectionAlias",
"order"
],
"children": [
{
"operatorType": "Apply@neo4j",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_20",
"anon_21",
"anon_1",
"organization",
"order"
],
"children": [
{
"operatorType": "Filter@neo4j",
"Details": "organization:Organization AND anon_1.fieldName = \"buyer\" AND organization.tenantId = \"853357c4-28f3-4f69-b95a-7ee38363e798\"",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_1",
"organization",
"order"
],
"children": [
{
"operatorType": "Expand(All)@neo4j",
"Details": "(order)-[anon_1:RELATES_TO]->(organization)",
"EstimatedRows": 0.1584807429686049,
"identifiers": [
"anon_1",
"organization",
"order"
],
"children": [
{
"operatorType": "Argument@neo4j",
"Details": "order",
"EstimatedRows": 0.051043379947513935,
"identifiers": [
"order"
],
"children": []
}
]
}
]
},
{
"operatorType": "EagerAggregation@neo4j",
"Details": "count(catalog) AS anon_20, collect(catalog{_id: id(catalog), .*}) AS anon_21",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_20",
"anon_21"
],
"children": [
{
"operatorType": "Filter@neo4j",
"Details": "catalog:Catalog AND anon_2.fieldName = \"category1\" AND catalog.tenantId = \"853357c4-28f3-4f69-b95a-7ee38363e798\"",
"EstimatedRows": 1.9365575603626337e-7,
"identifiers": [
"catalog",
"organization",
"anon_2"
],
"children": [
{
"operatorType": "Expand(All)@neo4j",
"Details": "(organization)-[anon_2:RELATES_TO]->(catalog)",
"EstimatedRows": 0.0008481053373955613,
"identifiers": [
"catalog",
"organization",
"anon_2"
],
"children": [
{
"operatorType": "Argument@neo4j",
"Details": "organization",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"organization"
],
"children": []
}
]
}
]
}
]
}
]
}
]
}
]
},
{
"operatorType": "EagerAggregation@neo4j",
"Details": "count(catalog) AS anon_22, collect(catalog{_id: id(catalog), .*}) AS anon_23",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_22",
"anon_23"
],
"children": [
{
"operatorType": "Filter@neo4j",
"Details": "catalog:Catalog AND anon_3.fieldName = \"category2\" AND catalog.tenantId = \"853357c4-28f3-4f69-b95a-7ee38363e798\"",
"EstimatedRows": 1.9365575603626337e-7,
"identifiers": [
"catalog",
"organization",
"anon_3"
],
"children": [
{
"operatorType": "Expand(All)@neo4j",
"Details": "(organization)-[anon_3:RELATES_TO]->(catalog)",
"EstimatedRows": 0.0008481053373955613,
"identifiers": [
"catalog",
"organization",
"anon_3"
],
"children": [
{
"operatorType": "Argument@neo4j",
"Details": "organization",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"organization"
],
"children": []
}
]
}
]
}
]
}
]
}
]
}
]
},
{
"operatorType": "EagerAggregation@neo4j",
"Details": "count(catalog) AS anon_24, collect(catalog{_id: id(catalog), .*}) AS anon_25",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"anon_24",
"anon_25"
],
"children": [
{
"operatorType": "Filter@neo4j",
"Details": "catalog:Catalog AND anon_4.fieldName = \"category3\" AND catalog.tenantId = \"853357c4-28f3-4f69-b95a-7ee38363e798\"",
"EstimatedRows": 1.9365575603626337e-7,
"identifiers": [
"catalog",
"organization",
"anon_4"
],
"children": [
{
"operatorType": "Expand(All)@neo4j",
"Details": "(organization)-[anon_4:RELATES_TO]->(catalog)",
"EstimatedRows": 0.0008481053373955613,
"identifiers": [
"catalog",
"organization",
"anon_4"
],
"children": [
{
"operatorType": "Argument@neo4j",
"Details": "organization",
"EstimatedRows": 0.00007163826404597566,
"identifiers": [
"organization"
],
"children": []
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
}
}
],
"errors": []
}