Chapter 2: Understanding Explain Quiz

No way of knowing wihtout the data for the inputStage whether Index Scan was used or not, this making it difficult for one to deduce if:

  • A sort was used in the first place or not
  • If it was used, whether it benefited or hampered the query
  • Making the option The index selected for the query was not useful for the sort part of the query irrelevant.

Hey @Mohammed_Ali_Zubair,

Welcome to the MongoDB Community Forums! :leaves:

"executionStats" : {
  "executionSuccess" : true,
  "nReturned" : 23217,
  "executionTimeMillis" : 91,
  "totalKeysExamined" : 23217,
  "totalDocsExamined" : 23217,
  "executionStages" : {
    "stage" : "SORT",
    "nReturned" : 23217,
    "executionTimeMillisEstimate" : 26,
    "works" : 46437,
    "advanced" : 23217,
    "needTime" : 23219,
    "needYield" : 0,
    "saveState" : 363,
    "restoreState" : 363,
    "isEOF" : 1,
    "sortPattern" : {
      "stars" : 1
    },
    "memUsage" : 32522511,
    "memLimit" : 33554432,

We have been given the above explain output.

  • A sort was used in the first place or not

Since it mentions stage: SORT in the execution stats, we can deduce that the SORT was performed.

  • If it was used, whether it benefited or hampered the query

This isn’t the ask of the question. There will be later chapters where we’ll learn more about indexes, reading explain plans, improving our indexes and many other things

The index selected for the query was not useful for the sort part of the query irrelevant.

This option is not irrelevant. Since the explain output shows that a SORT was performed, we can deduce that the index was not very useful for our query. Had it been useful, we would not have required a SORT stage and the sort would have been achieved with the index itself.

Please let us know if there are any doubts about this. I would also suggest you re-watch the video lecture if there’s any confusion around any concept. I also know it’s been a late reply so kindly let us know if the doubts have been already resolved.

Regards,
Satyam