Skip to content

Commit fe0a03a

Browse files
committed
wip: perf: improve query memory usage of collect fields
Instead of collecting { root, obj } pairs in a list, we now generate the whole collect result including field selection in one subquery. WIP: filtering, sorting and pagination not implemented yet WIP: InMemoryAdapter (do this last when we're sure about the query tree API)
1 parent 74e41e4 commit fe0a03a

File tree

71 files changed

+1622
-2095
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1622
-2095
lines changed

spec/dev/model/simple.graphqls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Skill @valueObject {
5050
}
5151

5252
"A superhero movie"
53-
type Movie @rootEntity @roles(read: ["logistics-reader"]) {
53+
type Movie @rootEntity {
5454
name: String
5555
"All the heroes starring in this movie"
5656
heroes: [Hero] @relation
@@ -71,6 +71,7 @@ type Movie @rootEntity @roles(read: ["logistics-reader"]) {
7171
type Director @rootEntity {
7272
name: String
7373
movies: [Movie] @relation(inverseOf: "director")
74+
allMissions: [Mission] @collect(path: "movies.heroes.missions", aggregate: DISTINCT)
7475
}
7576

7677
"A description of a hero suit"

spec/regression/collect/model/model.graphqls

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type Shipment @rootEntity {
1010
allHandlingUnits: [HandlingUnit]
1111
@collect(path: "deliveries.allHandlingUnits", aggregate: DISTINCT)
1212
allOrders: [Order] @collect(path: "deliveries.order", aggregate: DISTINCT)
13+
allInvoices: [Invoice] @collect(path: "deliveries.invoices")
1314
allDeliveryContents: [DeliveryContent] @collect(path: "deliveries.deliveryContents")
1415
allItems: [DeliveryItem] @collect(path: "deliveries.deliveryContents.items")
1516
totalWeightInKg: Decimal3 @collect(path: "allItems.weightInKg", aggregate: SUM)
@@ -38,6 +39,7 @@ type Delivery @rootEntity {
3839
handlingUnits: [HandlingUnit] @relation
3940
shipment: Shipment @relation(inverseOf: "deliveries")
4041
order: Order @relation
42+
invoices: [Invoice] @relation
4143

4244
allItems: [DeliveryItem] @collect(path: "deliveryContents.items")
4345
allItemNumbers: [String]
@@ -109,6 +111,14 @@ type Order @rootEntity {
109111
allItems: [DeliveryItem] @collect(path: "delivery.allItems")
110112
}
111113

114+
type Invoice @rootEntity {
115+
invoiceNumber: String @key
116+
accessGroup: String
117+
location: Location @accessField
118+
119+
delivery: Delivery @relation(inverseOf: "invoices")
120+
}
121+
112122
type DeliveryContent @childEntity {
113123
deliveryContentNumber: String
114124

spec/regression/collect/test-data.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,18 @@
250250
"warehouse": "North",
251251
"level": 0
252252
}
253+
},
254+
{
255+
"@id": "5",
256+
"handlingUnitNumber": "H5",
257+
"accessGroup": "H5",
258+
"location": {
259+
"identCode": "licH5"
260+
},
261+
"warehouseSlot": {
262+
"warehouse": "North",
263+
"level": 0
264+
}
253265
}
254266
],
255267
"Order": [
@@ -286,6 +298,44 @@
286298
"identCode": "licO4"
287299
}
288300
}
301+
],
302+
"Invoice": [
303+
{
304+
"@id": "1",
305+
"invoiceNumber": "I1",
306+
"accessGroup": "I1",
307+
"location": { "identCode": "licI1" }
308+
},
309+
{
310+
"@id": "2",
311+
"invoiceNumber": "I2",
312+
"accessGroup": "I2",
313+
"location": { "identCode": "licI2" }
314+
},
315+
{
316+
"@id": "3",
317+
"invoiceNumber": "I3",
318+
"accessGroup": "I3",
319+
"location": { "identCode": "licI3" }
320+
},
321+
{
322+
"@id": "4",
323+
"invoiceNumber": "I4",
324+
"accessGroup": "I4",
325+
"location": { "identCode": "licI4" }
326+
},
327+
{
328+
"@id": "5",
329+
"invoiceNumber": "I5",
330+
"accessGroup": "I5",
331+
"location": { "identCode": "licI5" }
332+
},
333+
{
334+
"@id": "6",
335+
"invoiceNumber": "I6",
336+
"accessGroup": "D6",
337+
"location": { "identCode": "licI6" }
338+
}
289339
]
290340
}
291341
}

spec/regression/collect/tests/collect-edge-count/aql/deleteDelivery.aql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ RETURN (
2626

2727
// --------------------------------
2828

29+
RETURN (
30+
FOR v_from1 IN (FOR v_id1 IN @v_ids1 RETURN CONCAT(@var1, v_id1))
31+
FOR v_edge1 IN @@deliveries_invoices
32+
FILTER v_edge1._from == v_from1
33+
REMOVE v_edge1 IN @@deliveries_invoices
34+
)
35+
36+
// --------------------------------
37+
2938
RETURN (
3039
FOR v_to1 IN (FOR v_id1 IN @v_ids1 RETURN CONCAT(@var1, v_id1))
3140
FOR v_edge1 IN @@shipments_deliveries

spec/regression/collect/tests/field-traversal/aql/fields.aql

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ LET v_delivery1 = FIRST((
77
))
88
RETURN {
99
"Delivery": (IS_NULL(v_delivery1) ? null : {
10-
"allItems": (
11-
FOR v_deliveryItem1
12-
IN v_delivery1.`deliveryContents`[*].`items`[*][**]
13-
RETURN {
14-
"itemNumber": v_deliveryItem1.`itemNumber`
15-
}
16-
)
10+
"allItems": v_delivery1.`deliveryContents`[*].`items`[* RETURN {
11+
"itemNumber": CURRENT.`itemNumber`
12+
}][**]
1713
})
1814
}

spec/regression/collect/tests/input-type-compat/aql/create.aql

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ RETURN (IS_NULL(v_delivery1) ? null : {
1414
COLLECT WITH COUNT INTO v_count1
1515
RETURN v_count1
1616
),
17-
"allItems": (
18-
FOR v_deliveryItem1
19-
IN v_delivery1.`deliveryContents`[*].`items`[*][**]
20-
RETURN {
21-
"itemNumber": v_deliveryItem1.`itemNumber`
22-
}
23-
)
17+
"allItems": v_delivery1.`deliveryContents`[*].`items`[* RETURN {
18+
"itemNumber": CURRENT.`itemNumber`
19+
}][**]
2420
})
2521

2622
// --------------------------------

spec/regression/collect/tests/input-type-compat/aql/update.aql

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ RETURN (IS_NULL(v_delivery1) ? null : {
2525
COLLECT WITH COUNT INTO v_count1
2626
RETURN v_count1
2727
),
28-
"allItems": (
29-
FOR v_deliveryItem1
30-
IN v_delivery1.`deliveryContents`[*].`items`[*][**]
31-
RETURN {
32-
"itemNumber": v_deliveryItem1.`itemNumber`
33-
}
34-
)
28+
"allItems": v_delivery1.`deliveryContents`[*].`items`[* RETURN {
29+
"itemNumber": CURRENT.`itemNumber`
30+
}][**]
3531
})
3632

3733
// --------------------------------

spec/regression/collect/tests/recursive-relation-traversal-access-group/aql/direct0to1.aql

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ LET v_delivery1 = FIRST((
1414
RETURN {
1515
"Delivery": (IS_NULL(v_delivery1) ? null : {
1616
"allHandlingUnits0to1": (
17-
FOR v_handlingUnit1
18-
IN (
19-
FOR v_node1, v_edge1, v_path1 IN @var4..@var5 OUTBOUND v_delivery1 @@deliveries_handlingUnits
20-
FILTER (v_node1.`accessGroup` IN @var6)
21-
FOR v_node2, v_edge2, v_path2 IN @var7..@var8 OUTBOUND v_node1 @@handlingUnits_childHandlingUnits
22-
FILTER (v_node2.`accessGroup` IN @var9)
23-
FILTER v_node2._key != null
24-
RETURN v_node2
25-
)
26-
SORT (v_handlingUnit1.`handlingUnitNumber`)
17+
FOR v_node1, v_edge1, v_path1 IN @var4..@var5 OUTBOUND v_delivery1 @@deliveries_handlingUnits
18+
FILTER (v_node1.`accessGroup` IN @var6)
19+
FOR v_node2, v_edge2, v_path2 IN @var7..@var8 OUTBOUND v_node1 @@handlingUnits_childHandlingUnits
20+
FILTER (v_node2.`accessGroup` IN @var9)
21+
FILTER v_node2._key != null
22+
SORT (v_node2.`handlingUnitNumber`)
2723
RETURN {
28-
"handlingUnitNumber": v_handlingUnit1.`handlingUnitNumber`
24+
"handlingUnitNumber": v_node2.`handlingUnitNumber`
2925
}
3026
)
3127
})

spec/regression/collect/tests/recursive-relation-traversal-access-group/aql/direct0to2.aql

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,15 @@ LET v_delivery1 = FIRST((
1414
RETURN {
1515
"Delivery": (IS_NULL(v_delivery1) ? null : {
1616
"allHandlingUnits0to2": (
17-
FOR v_handlingUnit1
18-
IN (
19-
FOR v_node1, v_edge1, v_path1 IN @var4..@var5 OUTBOUND v_delivery1 @@deliveries_handlingUnits
20-
FILTER (v_node1.`accessGroup` IN @var6)
21-
FOR v_node2, v_edge2, v_path2 IN @var7..@var8 OUTBOUND v_node1 @@handlingUnits_childHandlingUnits
22-
PRUNE !((v_node2.`accessGroup` IN @var9))
23-
FILTER v_path2.vertices[*].`accessGroup` ALL IN @var10
24-
FILTER v_node2._key != null
25-
RETURN v_node2
26-
)
27-
SORT (v_handlingUnit1.`handlingUnitNumber`)
17+
FOR v_node1, v_edge1, v_path1 IN @var4..@var5 OUTBOUND v_delivery1 @@deliveries_handlingUnits
18+
FILTER (v_node1.`accessGroup` IN @var6)
19+
FOR v_node2, v_edge2, v_path2 IN @var7..@var8 OUTBOUND v_node1 @@handlingUnits_childHandlingUnits
20+
PRUNE !((v_node2.`accessGroup` IN @var9))
21+
FILTER v_path2.vertices[*].`accessGroup` ALL IN @var10
22+
FILTER v_node2._key != null
23+
SORT (v_node2.`handlingUnitNumber`)
2824
RETURN {
29-
"handlingUnitNumber": v_handlingUnit1.`handlingUnitNumber`
25+
"handlingUnitNumber": v_node2.`handlingUnitNumber`
3026
}
3127
)
3228
})

spec/regression/collect/tests/recursive-relation-traversal-access-group/aql/direct1to1.aql

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@ LET v_delivery1 = FIRST((
1414
RETURN {
1515
"Delivery": (IS_NULL(v_delivery1) ? null : {
1616
"allHandlingUnits1to1": (
17-
FOR v_handlingUnit1
18-
IN (
19-
FOR v_node1, v_edge1, v_path1 IN @var4..@var5 OUTBOUND v_delivery1 @@deliveries_handlingUnits
20-
FILTER (v_node1.`accessGroup` IN @var6)
21-
FOR v_node2, v_edge2, v_path2 IN @var7..@var8 OUTBOUND v_node1 @@handlingUnits_childHandlingUnits
22-
FILTER (v_node2.`accessGroup` IN @var9)
23-
FILTER v_node2._key != null
24-
RETURN v_node2
25-
)
26-
SORT (v_handlingUnit1.`handlingUnitNumber`)
17+
FOR v_node1, v_edge1, v_path1 IN @var4..@var5 OUTBOUND v_delivery1 @@deliveries_handlingUnits
18+
FILTER (v_node1.`accessGroup` IN @var6)
19+
FOR v_node2, v_edge2, v_path2 IN @var7..@var8 OUTBOUND v_node1 @@handlingUnits_childHandlingUnits
20+
FILTER (v_node2.`accessGroup` IN @var9)
21+
FILTER v_node2._key != null
22+
SORT (v_node2.`handlingUnitNumber`)
2723
RETURN {
28-
"handlingUnitNumber": v_handlingUnit1.`handlingUnitNumber`
24+
"handlingUnitNumber": v_node2.`handlingUnitNumber`
2925
}
3026
)
3127
})

0 commit comments

Comments
 (0)