New in version 5.1.在版本5.1中新增。
To find and return query results, MongoDB uses one of the following query engines:为了查找和返回查询结果,MongoDB使用以下查询引擎之一:
The classic query engine经典查询引擎The slot-based query execution engine, which is available for some queries starting in MongoDB 5.1.基于槽的查询执行引擎,可用于MongoDB 5.1中开始的一些查询。
The slot-based query execution engine uses a "slot-based" model to avoid materialization of intermediate results during query runtime, which allows for more efficient execution.基于槽的查询执行引擎使用“基于槽”的模型来避免查询运行时中间结果的物化,从而实现更高效的执行。
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. MongoDB会自动选择执行查询的引擎。在早于8.0的MongoDB版本中,您无法手动为特定查询指定引擎。从MongoDB 8.0开始,您可以使用查询设置来指定查询引擎。For details, see 有关详细信息,请参阅setQuerySettings.setQuerySettings。
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.如果满足某些条件,MongoDB可以将基于槽的查询执行引擎用于查询的子集。在大多数情况下,与经典查询引擎相比,基于槽的执行引擎提供了更高的性能和更低的CPU和内存成本。
MongoDB uses the classic engine for queries that are ineligible for the slot-based query execution engine.MongoDB使用经典引擎处理不符合基于槽的查询执行引擎的查询。
Eligible Queries for the Slot-Based Execution Engine基于插槽的执行引擎的合格查询
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. MongoDB根据每个查询确定使用基于槽的执行引擎的资格,并考虑对查询中存在的每个运算符和表达式的支持。For example, two common pipelines that use slot-based execution engine are aggregations with 例如,使用基于槽的执行引擎的两个常见管道是具有$group or $lookup stages. However, support for the slot-based execution engine is version specific and actively changing.$group或$lookup阶段的聚合。然而,对基于插槽的执行引擎的支持是特定于版本的,并且正在不断变化。
To see whether your query used the slot-based execution engine, refer to the Determine which Query Engine was Used section.要查看查询是否使用了基于插槽的执行引擎,请参阅确定使用了哪个查询引擎一节。
Important
Block Processing块处理
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. 从8.0版本开始,MongoDB可以使用块处理执行某些时间序列查询。这种性能改进以数据的“块”而不是单个值来处理查询。Block processing improves query execution speed and throughput when working with time series collections.在处理时间序列集合时,块处理可以提高查询执行速度和吞吐量。
To learn more, see Querying Time Series Data.要了解更多信息,请参阅查询时间序列数据。
Determine which Query Engine was Used确定使用了哪个查询引擎
There are a few ways to determine whether the classic engine or the slot-based execution engine was used to execute a query.有几种方法可以确定是使用经典引擎还是基于槽的执行引擎来执行查询。
Check Query Explain Results检查查询解释结果
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 查询的解释结果因使用的查询引擎而异。例如,使用基于槽的执行引擎执行的查询的解释结果包括explain.queryPlanner.winningPlan.slotBasedPlan field.explain.queryPlanner.winningPlan.slotBasedPlan字段。
For more information about the differences in explain results between query engines, see Explain Output Structure.有关查询引擎之间解释结果差异的更多信息,请参阅解释输出结构。
Check Slow Query Logs检查慢速查询日志
Slow operation log messages include a 慢速操作日志消息包括一个queryFramework field that indicates which query engine executed the query:queryFramework字段,该字段指示哪个查询引擎执行了查询:
queryFramework: "classic"indicates that the classic engine executed the query.表示经典引擎执行了查询。queryFramework: "sbe"indicates that the slot-based query execution engine executed the query.表示基于槽的查询执行引擎执行了该查询。
To see an example log message for a query that used the slot-based execution engine, see Slow Operation.要查看使用基于槽的执行引擎的查询的示例日志消息,请参阅慢速操作。