Skip to content

Commit b847810

Browse files
authored
DOC-734 | AQL optimization: COLLECT ... AGGREGATE can utilize persistent index (#732)
* AQL optimization: COLLECT ... AGGREGATE can utilize persistent index * Julia's feedback * Can't call COUNT() in AGGREGATE either
1 parent c49e24f commit b847810

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

site/content/3.12/release-notes/version-3.12/whats-new-in-3-12.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,42 @@ to some extent.
12571257
See the [`COLLECT` operation](../../aql/high-level-operations/collect.md#disableindex)
12581258
for details.
12591259

1260+
---
1261+
1262+
<small>Introduced in: v3.12.5</small>
1263+
1264+
The `use-index-for-collect` optimizer rule has been further extended.
1265+
Queries where a `COLLECT` operation has an `AGGREGATE` clause that exclusively
1266+
refers to attributes covered by a persistent index (and no other variables nor
1267+
contains calls of aggregation functions with constant values) can now utilize
1268+
this index. The index must not be sparse.
1269+
1270+
Reading the data from the index instead of the stored documents for aggregations
1271+
can increase the performance by a factor of two.
1272+
1273+
```aql
1274+
FOR doc IN coll
1275+
COLLECT a = doc.a AGGREGATE b = MAX(doc.b)
1276+
RETURN { a, b }
1277+
```
1278+
1279+
If there is a persistent index over the attributes `a` and `b`, then the above
1280+
example query has an `IndexCollectNode` in the explain output and the index
1281+
usage is indicated if the optimization is applied:
1282+
1283+
```aql
1284+
Execution plan:
1285+
Id NodeType Par Est. Comment
1286+
1 SingletonNode 1 * ROOT
1287+
10 IndexCollectNode 4999 - FOR doc IN coll COLLECT a = doc.`a` AGGREGATE b = MAX(doc.`b`) /* full index scan */
1288+
6 CalculationNode ✓ 4999 - LET #5 = { "a" : a, "b" : b } /* simple expression */
1289+
7 ReturnNode 4999 - RETURN #5
1290+
1291+
Indexes used:
1292+
By Name Type Collection Unique Sparse Cache Selectivity Fields Stored values Ranges
1293+
10 idx_1836452431376941056 persistent coll
1294+
```
1295+
12601296
## Indexing
12611297

12621298
### Multi-dimensional indexes

site/content/3.13/release-notes/version-3.12/whats-new-in-3-12.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,42 @@ to some extent.
12571257
See the [`COLLECT` operation](../../aql/high-level-operations/collect.md#disableindex)
12581258
for details.
12591259

1260+
---
1261+
1262+
<small>Introduced in: v3.12.5</small>
1263+
1264+
The `use-index-for-collect` optimizer rule has been further extended.
1265+
Queries where a `COLLECT` operation has an `AGGREGATE` clause that exclusively
1266+
refers to attributes covered by a persistent index (and no other variables nor
1267+
contains calls of aggregation functions with constant values) can now utilize
1268+
this index. The index must not be sparse.
1269+
1270+
Reading the data from the index instead of the stored documents for aggregations
1271+
can increase the performance by a factor of two.
1272+
1273+
```aql
1274+
FOR doc IN coll
1275+
COLLECT a = doc.a AGGREGATE b = MAX(doc.b)
1276+
RETURN { a, b }
1277+
```
1278+
1279+
If there is a persistent index over the attributes `a` and `b`, then the above
1280+
example query has an `IndexCollectNode` in the explain output and the index
1281+
usage is indicated if the optimization is applied:
1282+
1283+
```aql
1284+
Execution plan:
1285+
Id NodeType Par Est. Comment
1286+
1 SingletonNode 1 * ROOT
1287+
10 IndexCollectNode 4999 - FOR doc IN coll COLLECT a = doc.`a` AGGREGATE b = MAX(doc.`b`) /* full index scan */
1288+
6 CalculationNode ✓ 4999 - LET #5 = { "a" : a, "b" : b } /* simple expression */
1289+
7 ReturnNode 4999 - RETURN #5
1290+
1291+
Indexes used:
1292+
By Name Type Collection Unique Sparse Cache Selectivity Fields Stored values Ranges
1293+
10 idx_1836452431376941056 persistent coll
1294+
```
1295+
12601296
## Indexing
12611297

12621298
### Multi-dimensional indexes

0 commit comments

Comments
 (0)