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
readon the database.
Ask for the plan
JavaScript
db.orders.find({ customer: "Ana Ruiz" }).sort({ created: -1 }).explain("executionStats");What to look at
| Field | What it says |
|---|---|
winningPlan | The chosen plan, with the index it uses. |
totalDocsExamined against nReturned | If it reads many more documents than it returns, an index is missing. |
| TeselaDB's own stages | The 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,
explaingives noslotBasedPlan;executionStagesdescribes TeselaDB's plan.