jstests/libs/analyze_plan.js
/**
 * Verifies that a given query uses an index and is covered when used in a count command.
 */
Verifies that a given query uses an index and is covered when used in a count command.
Verifies that a given query uses an index and is covered when used in a count command .
function assertCoveredQueryAndCount({collection, query, project, count}) {
    let explain = collection.find(query, project).explain();
    assert(isIndexOnly(db, getWinningPlan(explain.queryPlanner)),
           "Winning plan was not covered: " + tojson(explain.queryPlanner.winningPlan));
    explain = collection.explain("executionStats").find(query).count();
    assert(isIndexOnly(db, getWinningPlan(explain.queryPlanner)),
           "Winning plan for count was not covered: " + tojson(explain.queryPlanner.winningPlan));
    assertExplainCount({explainResults: explain, expectedCount: count});
}
function assertCoveredQueryAndCount ( { collection , query , project , count } ) { let explain = collection . find ( query , project ) . explain ( ) ; assert ( isIndexOnly ( db , getWinningPlan ( explain . queryPlanner ) ) , "Winning plan was not covered: " + tojson ( explain . queryPlanner . winningPlan ) ) ; explain = collection . explain ( "executionStats" ) . find ( query ) . count ( ) ; assert ( isIndexOnly ( db , getWinningPlan ( explain . queryPlanner ) ) , "Winning plan for count was not covered: " + tojson ( explain . queryPlanner . winningPlan ) ) ; assertExplainCount ( { explainResults : explain , expectedCount : count } ) ; }
Verifies that a given query uses an index and is covered when used in a count command.
Verifies that a given query uses an index and is covered when used in a count command .
// Same query as a count command should also be covered.