MongoDB - explain.executionStats
MongoDB - explain.executionStats
在 MongoDB 的解释 ("executionStats") 的输出中是否有任何元素给出了一个想法或提示 - 查询是否使用给定的索引进行过滤或排序或对于两者?
我阅读了以下URLs
[指向下方URL并进行简短讨论]
https://emptysqua.re/blog/optimizing-mongodb-compound-indexes/ [这个给出了总体思路,但是解释输出使用了旧的 format/elements,而我正在使用的 Mongodb 4.0 中不存在这些 format/elements]
https://docs.mongodb.com/manual/tutorial/sort-results-with-indexes/ [记录了如何确定索引和利用索引前缀,但确实显示了确认用法的解释输出]
来自 MongoDB Docs:
If MongoDB can use an index scan to obtain the requested sort order,
the result will not include a SORT stage. Otherwise, if MongoDB cannot
use the index to sort, the explain result will include a SORT stage.
示例:
查看 sortop 集合中的示例数据。
解释没有索引的查询计划:
为集合创建索引:
运行 解释计划中的相同查询和检查 SORT 阶段:
在 MongoDB 的解释 ("executionStats") 的输出中是否有任何元素给出了一个想法或提示 - 查询是否使用给定的索引进行过滤或排序或对于两者?
我阅读了以下URLs
https://emptysqua.re/blog/optimizing-mongodb-compound-indexes/ [这个给出了总体思路,但是解释输出使用了旧的 format/elements,而我正在使用的 Mongodb 4.0 中不存在这些 format/elements]
https://docs.mongodb.com/manual/tutorial/sort-results-with-indexes/ [记录了如何确定索引和利用索引前缀,但确实显示了确认用法的解释输出]
来自 MongoDB Docs:
If MongoDB can use an index scan to obtain the requested sort order, the result will not include a SORT stage. Otherwise, if MongoDB cannot use the index to sort, the explain result will include a SORT stage.
示例:
查看 sortop 集合中的示例数据。
解释没有索引的查询计划:
为集合创建索引:
运行 解释计划中的相同查询和检查 SORT 阶段: