在问这个问题之前,我确实通读了一下https://docs.mongodb.com/manual/tutorial/sort-results-with-indexes/来理解。
我们在explain()输出中寻找什么来确定给定的索引是否用于辅助查询的排序部分?
当对任何查询运行explain()时,我们可以看到使用了哪个索引和一些片段,如下所示
"winningPlan" : {
"stage" : "SORT",
"sortPattern" : {
"numReviews" : 1,
"rating" : -1
},这是否足以说明查询正在使用给定的索引进行排序?
发布于 2019-05-02 03:40:25
SORT阶段的出现表明查询规划器正在对内存中的结果进行排序。
如果使用索引扫描对结果进行排序,则explain计划的结果将为not include a SORT stage。
https://stackoverflow.com/questions/55940876
复制相似问题