Read a plan with explain

Use `explain` to see which index a query used, which ranges it touched and how much it read.

See how a query ran with explain: which index it used, which ranges it touched and how many documents it read to return the ones it returned.

Requirements

  • A connection with a user that has read on the database.

Ask for the plan

JavaScript
db.orders.find({ customer: "Ana Ruiz" }).sort({ created: -1 }).explain("executionStats");

What to look at

FieldWhat it says
winningPlanThe chosen plan, with the index it uses.
totalDocsExamined against nReturnedIf it reads many more documents than it returns, an index is missing.
TeselaDB's own stagesThe ranges touched, the split, the merge of buckets and the spills.

Check

After creating the missing index, totalDocsExamined drops until it gets close to nReturned in the same explain.

Common problems

  • With the SBE engine, explain gives no slotBasedPlan; executionStages describes TeselaDB's plan.

See also