<section>
 <h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
  Slot-Based Query Execution Engine
  <a class="headerlink leafygreen-ui-1kepx47" href="#slot-based-query-execution-engine" title="Permalink to this heading">
   <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
    <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
    </path>
    <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
    </path>
   </svg>
   <div class="css-1btu0w3 evvkmar0" id="slot-based-query-execution-engine">
   </div>
  </a>
 </h1>
 <div class="leafygreen-ui-a5yxub">
  <p class="css-1cmx2d4 ef7gu8j0">
   On this page
  </p>
  <ul class="css-1qb0mst ef7gu8j1">
   <li class="leafygreen-ui-1e7a0ei">
    <a class="lg-ui-0001 leafygreen-ui-e98ikf" href="#eligible-queries-for-the-slot-based-execution-engine" target="_self">
     <span>
      Eligible Queries for the Slot-Based Execution Engine
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#block-processing" target="_self">
     <span>
      Block Processing
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#determine-which-query-engine-was-used" target="_self">
     <span>
      Determine which Query Engine was Used
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#check-query-explain-results" target="_self">
     <span>
      Check Query Explain Results
     </span>
    </a>
   </li>
   <li class="leafygreen-ui-1jqtqlb">
    <a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#check-slow-query-logs" target="_self">
     <span>
      Check Slow Query Logs
     </span>
    </a>
   </li>
  </ul>
 </div>
 <div>
  <p>
   <em>
    New
    <!-- -->
    in version
    <!-- -->
    5.1
   </em>
   .
  </p>
 </div>
 <p class="leafygreen-ui-1kp3ins">
  To find and return query results, MongoDB uses one of the following
query engines:
 </p>
 <ul class="leafygreen-ui-rioki0">
  <li class="leafygreen-ui-d7p7b6">
   <p class="leafygreen-ui-1kp3ins">
    The classic query engine
   </p>
  </li>
  <li class="leafygreen-ui-d7p7b6">
   <p class="leafygreen-ui-1kp3ins">
    The slot-based query execution engine, which is available for some queries starting in MongoDB
5.1.
   </p>
  </li>
 </ul>
 <p class="leafygreen-ui-1kp3ins">
  MongoDB automatically selects the engine to execute the query. In
MongoDB versions earlier than 8.0, you cannot manually specify an engine
for a particular query. Starting in MongoDB 8.0, you can use
query settings to specify an engine for queries. For details, see
  <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setQuerySettings/#mongodb-dbcommand-dbcmd.setQuerySettings">
   <code class="leafygreen-ui-1l06pbn">
    setQuerySettings
   </code>
   .
  </a>
 </p>
 <p class="leafygreen-ui-1kp3ins">
  MongoDB can use the slot-based query execution engine for a subset of queries provided certain
conditions are met. In most cases, the slot-based execution engine provides improved
performance and lower CPU and memory costs compared to the classic query
engine.
 </p>
 <p class="leafygreen-ui-1kp3ins">
  MongoDB uses the classic engine for queries that are ineligible for the
slot-based query execution engine.
 </p>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Eligible Queries for the Slot-Based Execution Engine
   <a class="headerlink leafygreen-ui-1kepx47" href="#eligible-queries-for-the-slot-based-execution-engine" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="eligible-queries-for-the-slot-based-execution-engine">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   MongoDB determines eligibility for using the slot-based execution engine on a per-query basis,
and considers support for each operator and expressions present in the query.
For example, two common pipelines that use slot-based execution engine are aggregations with
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
    <code class="leafygreen-ui-1l06pbn">
     $group
    </code>
   </a>
   or
   <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup">
    <code class="leafygreen-ui-1l06pbn">
     $lookup
    </code>
   </a>
   stages. However, support for the
slot-based execution engine is version specific and actively changing.
  </p>
  <p class="leafygreen-ui-1kp3ins">
   To see whether your query used the slot-based execution engine, refer to the
   <a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sbe-determine-query-engine" target="_self">
    <span>
     Determine which Query Engine was Used
    </span>
   </a>
   section.
  </p>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Block Processing
    <a class="headerlink leafygreen-ui-1kepx47" href="#block-processing" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="block-processing">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Starting in version 8.0, MongoDB may execute certain time series queries using
block processing. This performance improvement processes queries in "blocks" of
data, rather than individual values. Block processing improves query execution
speed and throughput when working with time series collections.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    To learn more, see
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-querying/#std-label-timeseries-querying-block-processing">
     Querying Time Series Data
     <!-- -->
     .
    </a>
   </p>
   <span class="leafygreen-ui-1qnjd6d" id="std-label-sbe-determine-query-engine">
   </span>
  </section>
 </section>
 <section>
  <h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
   Determine which Query Engine was Used
   <a class="headerlink leafygreen-ui-1kepx47" href="#determine-which-query-engine-was-used" title="Permalink to this heading">
    <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
     <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
     </path>
     <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
     </path>
    </svg>
    <div class="css-1btu0w3 evvkmar0" id="determine-which-query-engine-was-used">
    </div>
   </a>
  </h2>
  <p class="leafygreen-ui-1kp3ins">
   There are a few ways to determine whether the classic engine or the
slot-based execution engine was used to execute a query.
  </p>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Check Query Explain Results
    <a class="headerlink leafygreen-ui-1kepx47" href="#check-query-explain-results" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="check-query-explain-results">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    The explain results for a query differ based on
which query engine was used. For example, explain results for queries
executed using the slot-based execution engine include the
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/explain-results/#mongodb-data-explain.queryPlanner.winningPlan.slotBasedPlan">
     <code class="leafygreen-ui-1l06pbn">
      explain.queryPlanner.winningPlan.slotBasedPlan
     </code>
    </a>
    field.
   </p>
   <p class="leafygreen-ui-1kp3ins">
    For more information about the differences in explain results between
query engines, see
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/explain-results/#std-label-explain-output-structure">
     Explain Output Structure
     <!-- -->
     .
    </a>
   </p>
  </section>
  <section>
   <h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
    Check Slow Query Logs
    <a class="headerlink leafygreen-ui-1kepx47" href="#check-slow-query-logs" title="Permalink to this heading">
     <svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
      <path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
      </path>
      <path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
      </path>
     </svg>
     <div class="css-1btu0w3 evvkmar0" id="check-slow-query-logs">
     </div>
    </a>
   </h3>
   <p class="leafygreen-ui-1kp3ins">
    Starting in MongoDB 6.2, slow operation log messages include a
    <code class="leafygreen-ui-1l06pbn">
     queryFramework
    </code>
    field that indicates which query engine executed the
query:
   </p>
   <ul class="leafygreen-ui-rioki0">
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      <code class="leafygreen-ui-1l06pbn">
       queryFramework: "classic"
      </code>
      indicates that the classic engine
executed the query.
     </p>
    </li>
    <li class="leafygreen-ui-d7p7b6">
     <p class="leafygreen-ui-1kp3ins">
      <code class="leafygreen-ui-1l06pbn">
       queryFramework: "sbe"
      </code>
      indicates that the slot-based query execution engine executed the
query.
     </p>
    </li>
   </ul>
   <p class="leafygreen-ui-1kp3ins">
    To see an example log message for a query that used the slot-based execution engine,
see
    <a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-json-examples-slow-op">
     Slow Operation
     <!-- -->
     .
    </a>
   </p>
  </section>
 </section>
</section>
