planCacheClear

On this page本页内容

Definition定义

planCacheClear

Removes cached query plans for a collection. 删除集合的缓存查询计划。Specify a query shape to remove cached query plans for that shape. 指定查询形状以删除该形状的缓存查询计划。Omit the query shape to clear all cached query plans.省略查询形状以清除所有缓存的查询计划。

The command has the following syntax:该命令具有以下语法:

db.runCommand(
   {
      planCacheClear: <collection>,
      query: <query>,
      sort: <sort>,
      projection: <projection>,
      comment: <any>
   }
)

The planCacheClear command has the following field:planCacheClear命令具有以下字段:

Field字段Type类型Description描述
querydocumentOptional. 可选。The query predicate of the query shape. 查询形状的查询谓词。Only the structure of the predicate, including the field names, are significant to the shape; the values in the query predicate are insignificant. 只有谓词的结构(包括域名)对形状有意义;查询谓词中的值无关紧要。
projectiondocumentOptional. 可选。The projection associated with the query shape.查询形状关联的投影。
sortdocumentOptional. 可选。The sort associated with the query shape.查询形状关联的排序。
commentany

Optional. 可选。A user-provided comment to attach to this command. 用户提供了附加到此命令的注释。Once set, this comment appears alongside records of this command in the following locations:设置后,此注释将与此命令的记录一起显示在以下位置:

A comment can be any valid BSON type(string, integer, object, array, etc).注释可以是任何有效的BSON类型(字符串、整数、对象、数组等)。

New in version 4.4.在版本4.4中新增

To see the query shapes for which cached query plans exist, see List Query Shapes.要查看存在缓存查询计划的查询形状,请参阅列出查询形状

Required Access所需访问权限

On systems running with authorization, a user must have access that includes the planCacheWrite action.在使用authorization运行的系统上,用户必须具有包括planCacheWrite操作的访问权限。

Examples示例

Clear Cached Plans for a Query Shape清除查询形状的缓存计划

If a collection orders has the following query shape:如果orders集合具有以下查询形状:

{
  "query" : { "qty" : { "$gt" : 10 } },
  "sort" : { "ord_date" : 1 },
  "projection" : { },
  "queryHash" : "9AAD95BE"  // Available starting in MongoDB 4.2
}

The following operation clears the query plan cached for the shape:以下操作将清除为形状缓存的查询计划:

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

Clear All Cached Plans for a Collection清除集合的所有缓存计划

The following example clears all the cached query plans for the orders collection:以下示例清除orders集合的所有缓存查询计划:

db.runCommand(
   {
      planCacheClear: "orders"
   }
)
Tip提示
←  Query Plan Cache CommandsplanCacheClearFilters →