planCacheListPlans

在本页面

Definition

显示指定的query shape的缓存查询计划。

查询优化器仅缓存那些具有多个可行计划的查询形状的计划。

mongo shell 为此命令提供了包装器PlanCache.getPlansByQuery()

planCacheListPlans命令具有以下语法:

db.runCommand(
   {
      planCacheListPlans: <collection>,
      query: <query>,
      sort: <sort>,
      projection: <projection>
   }

planCacheListPlans命令具有以下字段:

Field Type Description
query document query shape的查询谓词。仅谓词的结构(包括字段名)对形状很重要。查询谓词中的值无关紧要。
projection document 可选的。与query shape关联的投影。
sort document 可选的。与query shape关联的排序。

要查看存在缓存的查询计划的查询形状,请使用planCacheListQueryShapes命令。

3.6 版中的新增功能:planCacheListPlans数据库命令返回的输出与PlanCache.getPlansByQuery()方法相同。

Required Access

在运行authorization的系统上,用户必须具有包括planCacheRead操作的访问权限。

Example

如果集合orders具有以下查询形状:

{
  "query" : { "qty" : { "$gt" : 10 } },
  "sort" : { "ord_date" : 1 },
  "projection" : { }
}

以下操作显示为形状缓存的查询计划:

db.runCommand(
   {
      planCacheListPlans: "orders",
      query: { "qty" : { "$gt" : 10 } },
      sort: { "ord_date" : 1 }
   }
)
首页