Skip to content

Commit 2fbbd7a

Browse files
(DOCSP-19941): Support pushdown of to SBE (#229)
* (DOCSP-19941): Support pushdown of group to SBE * Updates per copy review * updates per external review * reformat * add clarification for allowDiskUse * technical tweaks * word tweak
1 parent e473868 commit 2fbbd7a

File tree

7 files changed

+78
-10
lines changed

7 files changed

+78
-10
lines changed

snooty.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,16 @@ toc_landing_pages = [
190190
]
191191

192192
[substitutions]
193+
bi = "MongoDB Connector for BI"
193194
compass = "MongoDB Compass"
194-
mdb-shell = "MongoDB Shell"
195195
copy = "©"
196196
ent-build = "MongoDB Enterprise"
197-
year = "2021"
198-
bi = "MongoDB Connector for BI"
197+
mdb-shell = "MongoDB Shell"
198+
sbe = "slot-based query execution engine"
199+
sbe-short = "slot-based engine"
200+
sbe-title = "Slot-Based Query Execution Engine"
199201
version = "{+version+}"
202+
year = "2022"
200203

201204

202205
[constants]

source/core/aggregation-pipeline-optimization.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ use any values computed in either the :pipeline:`$project` or
112112
:pipeline:`$match` stage before both of the projection stages.
113113

114114
.. note::
115+
115116
After optimization, the filter ``{ name: "Joe Schmoe" }`` is in
116117
a :pipeline:`$match` stage at the beginning of the pipeline. This has
117118
the added benefit of allowing the aggregation to use an index on the
@@ -383,6 +384,25 @@ option, the ``explain`` output shows the coalesced stage:
383384
}
384385
}
385386

387+
.. _agg-group-optimization-sbe:
388+
389+
``$group`` Optimization
390+
-----------------------
391+
392+
.. versionadded:: 5.2
393+
394+
.. include:: /includes/fact-sbe-group-overview.rst
395+
396+
To verify that the |sbe-short| is used, run the aggregation with the
397+
``.explain()`` option. This option outputs information on the
398+
aggregation's query plan.
399+
400+
When the |sbe| is used for :pipeline:`$group`, the :ref:`explain results
401+
<explain-results>` include:
402+
403+
- ``explain.explainVersion: '2'``
404+
- ``explain.queryPlanner.winningPlan.queryPlan.stage: "GROUP"``
405+
386406
Example
387407
-------
388408
.. _agg-sort-skip-limit-sequence:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Starting in MongoDB 5.2, MongoDB uses the
2+
:ref:`slot-based execution query engine <5.1-rel-notes-sbe>` to execute
3+
:pipeline:`$group` stages when :pipeline:`$group` is either:
4+
5+
- The first stage in the pipeline.
6+
7+
- Part of a series of stages executed by the |sbe-short| that
8+
occurs at the beginning of the pipeline. For example, if a pipeline
9+
begins with :pipeline:`$match` followed by :pipeline:`$group`, the
10+
:pipeline:`$match` and :pipeline:`$group` stages are executed by the
11+
|sbe-short|.
12+
13+
In most cases, the |sbe-short| provides improved performance and lower
14+
CPU and memory costs compared to the classic query engine.

source/reference/command/aggregate.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ arguments:
103103

104104
- boolean
105105

106-
- Optional. Enables writing to temporary files. When set to ``true``, aggregation
107-
stages can write data to the :file:`_tmp` subdirectory in the
108-
:setting:`~storage.dbPath` directory.
106+
- Optional. Enables writing to temporary files. When set to
107+
``true``, aggregation stages can write data to the :file:`_tmp`
108+
subdirectory in the :setting:`~storage.dbPath` directory.
109+
110+
By default, ``allowDiskUse`` is ``false``.
109111

110112
.. include:: /includes/extracts/4.2-changes-usedDisk.rst
111113

source/reference/explain-results.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,22 @@ The ``explain`` results present the query plans as a tree of stages.
5151
}
5252
},
5353

54-
Each stage passes its results (i.e. documents or index keys) to the
54+
Each stage passes its resulting documents or index keys to the
5555
parent node. The leaf nodes access the collection or the indices. The
5656
internal nodes manipulate the documents or the index keys that result
5757
from the child nodes. The root node is the final stage from which
5858
MongoDB derives the result set.
5959

60-
Stages are descriptive of the operation; e.g.
60+
Stages are descriptive of the operation. For example:
6161

6262
- ``COLLSCAN`` for a collection scan
6363

6464
- ``IXSCAN`` for scanning index keys
6565

6666
- ``FETCH`` for retrieving documents
6767

68+
- ``GROUP`` for grouping douments with :pipeline:`$group`
69+
6870
- ``SHARD_MERGE`` for merging results from shards
6971

7072
- ``SHARDING_FILTER`` for filtering out orphan documents from shards
@@ -207,6 +209,11 @@ This section shows the ``explain`` output for MongoDB 5.1 and later.
207209
instance, an ``IXSCAN`` stage will include the index bounds
208210
along with other data specific to the index scan.
209211

212+
Starting in MongoDB 5.2, MongoDB can execute :pipeline:`$group`
213+
stages using the :ref:`slot-based execution query engine
214+
<5.1-rel-notes-sbe>`. When the |sbe-short| is used for
215+
:pipeline:`$group`, this field value is ``GROUP``.
216+
210217
.. data:: explain.queryPlanner.winningPlan.queryPlan.planNodeId
211218

212219
Unique integer field that identifies each stage in the execution
@@ -217,7 +224,7 @@ This section shows the ``explain`` output for MongoDB 5.1 and later.
217224

218225
.. data:: explain.queryPlanner.winningPlan.slotBasedPlan
219226

220-
Document with information about the slot based query execution plan
227+
Document with information about the slot based query execution plan
221228
tree and stages.
222229

223230
.. versionadded:: 5.1

source/reference/operator/aggregation/group.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,15 @@ aggregation pipeline stages to write data to temporary files.
8989

9090
.. _group-pipeline-optimization:
9191

92+
``$group`` Performance Optimizations
93+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94+
95+
This section describes optimizations to improve the performance of
96+
:pipeline:`$group`. There are optimizations that you can make manually
97+
and optimizations MongoDB makes internally.
98+
9299
Optimization to Return the First Document of Each Group
93-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
100+
```````````````````````````````````````````````````````
94101

95102
If a pipeline :pipeline:`sorts <$sort>` and :pipeline:`groups <$group>`
96103
by the same field and the :pipeline:`$group` stage only uses the
@@ -119,6 +126,14 @@ the first document of each group.
119126
}
120127
])
121128

129+
|sbe-title|
130+
```````````
131+
132+
.. include:: /includes/fact-sbe-group-overview.rst
133+
134+
See :ref:`agg-group-optimization-sbe`.
135+
136+
122137
Examples
123138
--------
124139

source/release-notes/5.2.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ Starting in MongoDB 5.2, you can convert timestamps to dates using the
100100
:expression:`$convert` operator. The :expression:`$toDate` operator can
101101
also convert timestamps.
102102

103+
|sbe-title| Can Execute :pipeline:`$group` Stages
104+
`````````````````````````````````````````````````
105+
106+
.. include:: /includes/fact-sbe-group-overview.rst
107+
108+
See :ref:`agg-group-optimization-sbe`.
109+
103110
.. _5.2-rel-notes-sharding:
104111

105112
Sharding

0 commit comments

Comments
 (0)