Files
mongo/jstests/libs/query/join_utils.js
Ben Shteinfeld 1f44d4c7ce SERVER-113172 Insert join predicates from subpipelines into the JoinGraph (#45269)
GitOrigin-RevId: e611a246bd17f91cd5a6102a396631085461bfdd
2025-12-21 22:34:58 +00:00

20 lines
1.0 KiB
JavaScript

/**
* Utility functions for join optimization tests.
*/
import {getQueryPlanner} from "jstests/libs/query/analyze_plan.js";
// Runs the given test case with join optimization enabled and disabled, verifies that the results
// match expectedResults, and checks whether the join optimization was used as expected.
export function runTest({description, coll, pipeline, expectedResults, expectedUsedJoinOptimization}) {
print(`Running test: ${description}`);
assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: false}));
assert.eq(coll.aggregate(pipeline).toArray(), expectedResults);
assert.commandWorked(db.adminCommand({setParameter: 1, internalEnableJoinOptimization: true}));
assert.eq(coll.aggregate(pipeline).toArray(), expectedResults);
const explain = coll.explain().aggregate(pipeline);
print(`Explain: ${tojson(explain)}`);
const winningPlan = getQueryPlanner(explain).winningPlan;
assert.eq(expectedUsedJoinOptimization, winningPlan.usedJoinOptimization, winningPlan);
}