Slot-Based Query Execution Engine基于插槽的查询执行引擎
On this page本页内容
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中开始的一些查询。
MongoDB automatically selects the engine to execute the query. You cannot manually specify an engine for a particular query.MongoDB会自动选择执行查询的引擎。不能为特定查询手动指定引擎。
MongoDB can use the slot-based query execution engine for a subset of queries provided certain conditions are met. 只要满足某些条件,MongoDB就可以使用基于槽的查询执行引擎来执行查询的子集。In most cases, the slot-based execution engine provides improved performance and lower CPU and memory costs compared to the classic query engine.在大多数情况下,与传统的查询引擎相比,基于插槽的执行引擎提供了改进的性能以及更低的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 can use the slot-based execution engine for the following queries:MongoDB可以使用基于slot的执行引擎进行以下查询:
$group
and和$lookup
pipeline stages when specific conditions are met.满足特定条件时的管道阶段。For more information, see Slot-Based Query Execution Engine Pipeline Optimizations.有关更多信息,请参阅基于槽的查询执行引擎管道优化。$match
and和$project
pipeline stages that use supported query operators and expressions.使用支持的查询运算符和表达式的管道阶段。Certain某些不包括$sort
pipeline stages that do not include$meta
sorts.$meta
排序的$sort
管道阶段。find()
queries that use supported query operators and expressions.使用支持的查询运算符和表达式的查询。
The slot-based execution engine does not support geospatial query operators.基于插槽的执行引擎不支持地理空间查询运算符。
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检查慢速查询日志
Starting in MongoDB 6.2, slow operation log messages include a 从MongoDB 6.2开始,慢速操作日志消息包括一个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.要查看使用基于插槽的执行引擎的查询的示例日志消息,请参阅慢速操作。