@@ -387,24 +387,82 @@ option, the ``explain`` output shows the coalesced stage:
387
387
}
388
388
}
389
389
390
+ .. _sbe-pipeline-optimizations:
391
+
392
+ |sbe-title| Pipeline Optimizations
393
+ ----------------------------------
394
+
395
+ MongoDB can use the :ref:`slot-based execution query engine
396
+ <5.1-rel-notes-sbe>` to execute certain pipeline stages when specific
397
+ conditions are met. In most cases, the |sbe-short| provides improved
398
+ performance and lower CPU and memory costs compared to the classic query
399
+ engine.
400
+
401
+ To verify that the |sbe-short| is used, run the aggregation with the
402
+ ``explain`` option. This option outputs information on the
403
+ aggregation's query plan. For more information on using ``explain``
404
+ with aggregations, see :ref:`example-aggregate-method-explain-option`.
405
+
406
+ The following sections describe:
407
+
408
+ - The conditions when the |sbe-short| is used for aggregation.
409
+
410
+ - How to verify if the |sbe-short| was used.
411
+
390
412
.. _agg-group-optimization-sbe:
391
413
392
414
``$group`` Optimization
393
- -----------------------
415
+ ~~~~~~~~~~~~~~~~~~~~~~~
394
416
395
417
.. versionadded:: 5.2
396
418
397
419
.. include:: /includes/fact-sbe-group-overview.rst
398
420
399
- To verify that the |sbe-short| is used, run the aggregation with the
400
- ``.explain()`` option. This option outputs information on the
401
- aggregation's query plan.
402
-
403
421
When the |sbe| is used for :pipeline:`$group`, the :ref:`explain results
404
422
<explain-results>` include:
405
423
406
424
- ``explain.explainVersion: '2'``
407
- - ``explain.queryPlanner.winningPlan.queryPlan.stage: "GROUP"``
425
+ - ``queryPlanner.winningPlan.queryPlan.stage: "GROUP"``
426
+
427
+ The location of the ``queryPlanner`` object depends on whether the
428
+ pipeline contains stages after the ``$group`` stage which cannot be
429
+ executed using the |sbe-short|.
430
+
431
+ - If ``$group`` is the last stage or all stages after ``$group`` can
432
+ be executed using the |sbe-short|, the ``queryPlanner`` object is in
433
+ the top-level ``explain`` output object (``explain.queryPlanner``).
434
+
435
+ - If the pipeline contains stages after ``$group`` which cannot be
436
+ executed using the |sbe-short|, the ``queryPlanner`` object is in
437
+ ``explain.stages[0].$cursor.queryPlanner``.
438
+
439
+ .. _agg-lookup-optimization-sbe:
440
+
441
+ ``$lookup`` Optimization
442
+ ~~~~~~~~~~~~~~~~~~~~~~~~
443
+
444
+ .. versionadded:: 6.0
445
+
446
+ .. include:: /includes/fact-sbe-lookup-overview.rst
447
+
448
+ When the |sbe| is used for :pipeline:`$lookup`, the :ref:`explain
449
+ results <explain-results>` include:
450
+
451
+ - ``explain.explainVersion: '2'``
452
+ - ``queryPlanner.winningPlan.queryPlan.stage: "EQ_LOOKUP"``.
453
+ ``EQ_LOOKUP`` means "equality lookup".
454
+
455
+ The location of the ``queryPlanner`` object depends on whether the
456
+ pipeline contains stages after the ``$lookup`` stage which cannot be
457
+ executed using the |sbe-short|.
458
+
459
+ - If ``$lookup`` is the last stage or all stages after ``$lookup`` can
460
+ be executed using the |sbe-short|, the ``queryPlanner`` object is in
461
+ the top-level ``explain`` output object (``explain.queryPlanner``).
462
+
463
+ - If the pipeline contains stages after ``$lookup`` which cannot be
464
+ executed using the |sbe-short|, the ``queryPlanner`` object is in
465
+ ``explain.stages[0].$cursor.queryPlanner``.
408
466
409
467
.. _aggregation-pipeline-optimization-indexes-and-filters:
410
468
0 commit comments