liveBook · Manning

Classic query engine

As explained in MongoDB 8.0 in Action, Third Edition

The classic query engine is MongoDB's original query execution engine for planning and running database operations.

The classic query engine is MongoDB’s original engine for planning and executing database operations. MongoDB selects it automatically when a query does not meet the criteria for the slot-based query engine; applications cannot choose it manually. section 7.1.1

Use these signals to identify and assess classic-engine execution:

  • Inspect explain output: slot-based execution includes explain.queryPlanner.winningPlan.slotBasedPlan, while classic-engine results do not include that field. section 7.1.1
  • Check MongoDB logs for queryFramework: "classic" identifies classic execution, while "sbe" identifies slot-based execution. section 7.1.1
  • Treat engine choice as a performance consideration: the slot-based engine usually uses less CPU and memory and performs better, but the classic engine handles queries outside its eligibility criteria. section 7.1.1

Check the execution engine

Run db.collection.find({ yourField: "value" }).explain("executionStats") to inspect the winning plan and execution statistics. Review the output for slotBasedPlan; if it is absent, check the logs for queryFramework: "classic". The same explain output can show nReturned, executionTimeMillis, totalKeysExamined, and totalDocsExamined for performance diagnosis. section 7.1.1

Listing 7.1 Appending the MongoDB explain () method
db.collection.find(
    { yourField: "value" }
).explain() // Explain the default query planner information

db.collection.find(
    { yourField: "value" }
).explain(
    "executionStats" // Explain the query execution statistics
)

db.collection.find(
    { yourField: "value" }
).explain(
    "allPlansExecution" // Explain the query execution
➥plan with all possible query plans
)

Compare queryPlanner, executionStats, and allPlansExecution verbosity when investigating which plan and engine MongoDB used. section 7.1.1

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Identifies engines through explain fields and logs, but does not detail classic-engine internals or selection criteria.
Examples
Uses find().explain() output and queryFramework log values to distinguish classic from slot-based execution.
What it assumes
Assumes basic MongoDB query operations and introduces engine identification through explain results and logs.
What you can do after
Diagnose engine selection and query efficiency with explain verbosity levels and MongoDB log fields.
How it connects
Connects query execution with the slot-based query engine, query planner, indexes, explain plans, and MongoDB logs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.