jstests/noPassthrough/clustered_collection_sorted_scan.js
// Ensure that the plan gets cached correctly
Ensure that the plan gets cached correctly
Ensure that the plan gets cached correctly
function testPlanCache() {
    clusteredColl.getPlanCache().clear();
    const indexName = "_a";
    assert.commandWorked(clusteredColl.createIndex({a: 1}, {name: indexName}));
    let query = clusteredColl.find({a: {$gt: -1}}).sort({[clusterField]: -1});
    let plan = query.explain();
    assert(plan.queryPlanner.rejectedPlans.length > 0, tojson(plan));
    assert(planHasStage(testDb, plan, "COLLSCAN"), "Expected COLLSCAN in " + tojson(plan));
    query.toArray();
    let cacheEntries = clusteredColl.getPlanCache().list();
    let cachedPlan = cacheEntries.find(e => e.queryHash == plan.queryPlanner.queryHash);
    assert.neq(cachedPlan, null, "Plan not in cache");
    assert.commandWorked(clusteredColl.dropIndex(indexName));
}
function testPlanCache ( ) { clusteredColl . getPlanCache ( ) . clear ( ) ; const indexName = "_a" ; assert . commandWorked ( clusteredColl . createIndex ( { a : 1 } , { name : indexName } ) ) ; let query = clusteredColl . find ( { a : { $gt : - 1 } } ) . sort ( { [ clusterField ] : - 1 } ) ; let plan = query . explain ( ) ; assert ( plan . queryPlanner . rejectedPlans . length > 0 , tojson ( plan ) ) ; assert ( planHasStage ( testDb , plan , "COLLSCAN" ) , "Expected COLLSCAN in " + tojson ( plan ) ) ; query . toArray ( ) ; let cacheEntries = clusteredColl . getPlanCache ( ) . list ( ) ; let cachedPlan = cacheEntries . find ( e => e . queryHash == plan . queryPlanner . queryHash ) ; assert . neq ( cachedPlan , null , "Plan not in cache" ) ; assert . commandWorked ( clusteredColl . dropIndex ( indexName ) ) ; }
Ensure that the plan gets cached correctly
Ensure that the plan gets cached correctly
// Because of the _a index above, we should have two alternatves -- filter via the // index then a blocking sort, or filter during a collection scan. Because of the blocking // sort and the fact that "a" doesnt actually filter anything, we expect the // collection scan to win. // Run the query to ensure it's cached // Verify that there's a cache entry for this query