jstests/core/sbe_plan_cache_autoparameterize_collscan.js
/**
 * Runs a single end-to-end test case for auto-parameterization of collection scan plans.
 *  - 'shape1' is a description of a find command as a document {query: <filter>, projection:
 *  <projection>, sort: <sort>}.
 *  - 'expectedResults1' is an array containing the results expected from running 'shape1' against
 *  the test collection. This function verifies that the actual results match the expected ones.
 *  The order of the result set is not considered significant (since not all test queries specify a
 *  sort).
 *  - 'shape2' is a second find command, expressed with the same format as 'shape1' and whose
 *  results are compared to `expectedResults2'. Again, the order of the result set is not
 *  significant.
 *  - If 'sameCacheKey' is true, then verifies that 'shape1' and 'shape2' have the same plan cache
 *  key using $planCacheStats. Otherwise, verifies that the two test queries have different plan
 *  cache keys.
 *
 * Also uses $planCacheStats to verify that the expected cache entries are created.
 */
Runs a single end-to-end test case for auto-parameterization of collection scan plans.
- 'shape1' is a description of a find command as a document {query: , projection:
, sort: }.
- 'expectedResults1' is an array containing the results expected from running 'shape1' against
the test collection. This function verifies that the actual results match the expected ones.
The order of the result set is not considered significant (since not all test queries specify a
sort).

Also uses $planCacheStats to verify that the expected cache entries are created.
Runs a single end - to - end test case for auto - parameterization of collection scan plans . - ' shape1 ' is a description of a find command as a document { query : projection : sort : } . - ' expectedResults1 ' is an array containing the results expected from running ' shape1 ' against the test collection . This function verifies that the actual results match the expected ones . The order of the result set is not considered significant ( since not all test queries specify a sort ) . Also uses $planCacheStats to verify that the expected cache entries are created .
function runTest(shape1, expectedResults1, shape2, expectedResults2, sameCacheKey) {
    coll.getPlanCache().clear();
    for (let shape of [shape1, shape2]) {
        shape.collection = coll;
        shape.db = db;
    }
    const cacheKey1 = getPlanCacheKeyFromShape(shape1);
    const cacheKey2 = getPlanCacheKeyFromShape(shape2);
    if (sameCacheKey) {
        assert.eq(cacheKey1, cacheKey2, "expected SBE plan cache keys to be the same");
    } else {
        assert.neq(cacheKey1, cacheKey2, "expected SBE plan cache keys to be different");
    }
    [...Array(2)].forEach(() => {
        const actualResults1 = runFindCommandFromShapeDoc(shape1);
        assert.sameMembers(actualResults1, expectedResults1, shape1);
        assertSbePlanCacheEntryExists(cacheKey1);
        const actualResults2 = runFindCommandFromShapeDoc(shape2);
        assert.sameMembers(actualResults2, expectedResults2, shape2);
        assertSbePlanCacheEntryExists(cacheKey2);
    });
}
function runTest ( shape1 , expectedResults1 , shape2 , expectedResults2 , sameCacheKey ) { coll . getPlanCache ( ) . clear ( ) ; for ( let shape of [ shape1 , shape2 ] ) { shape . collection = coll ; shape . db = db ; } const cacheKey1 = getPlanCacheKeyFromShape ( shape1 ) ; const cacheKey2 = getPlanCacheKeyFromShape ( shape2 ) ; if ( sameCacheKey ) { assert . eq ( cacheKey1 , cacheKey2 , "expected SBE plan cache keys to be the same" ) ; } else { assert . neq ( cacheKey1 , cacheKey2 , "expected SBE plan cache keys to be different" ) ; } [ ... Array ( 2 ) ] . forEach ( ( ) => { const actualResults1 = runFindCommandFromShapeDoc ( shape1 ) ; assert . sameMembers ( actualResults1 , expectedResults1 , shape1 ) ; assertSbePlanCacheEntryExists ( cacheKey1 ) ; const actualResults2 = runFindCommandFromShapeDoc ( shape2 ) ; assert . sameMembers ( actualResults2 , expectedResults2 , shape2 ) ; assertSbePlanCacheEntryExists ( cacheKey2 ) ; } ) ; }
Runs a single end-to-end test case for auto-parameterization of collection scan plans.
Runs a single end - to - end test case for auto - parameterization of collection scan plans .
// Flush the cache before starting the test to make sure we are starting from a clean slate. // Run each query twice in order to make sure that each query still returns the same results // after the state of the cache has been altered.