diff options
Diffstat (limited to 'jstests/libs/analyze_plan.js')
| -rw-r--r-- | jstests/libs/analyze_plan.js | 92 |
1 files changed, 3 insertions, 89 deletions
diff --git a/jstests/libs/analyze_plan.js b/jstests/libs/analyze_plan.js index dc1f15dcb2c..dcfb3f11221 100644 --- a/jstests/libs/analyze_plan.js +++ b/jstests/libs/analyze_plan.js @@ -526,18 +526,9 @@ function getPlanCacheKeyFromExplain(explainRes, db) { * Helper to run a explain on the given query shape and get the "planCacheKey" from the explain * result. */ -function getPlanCacheKeyFromShape({ - query = {}, - projection = {}, - sort = {}, - collation = { - locale: "simple" - }, - collection, - db -}) { - const explainRes = assert.commandWorked( - collection.explain().find(query, projection).collation(collation).sort(sort).finish()); +function getPlanCacheKeyFromShape({query = {}, projection = {}, sort = {}, collection, db}) { + const explainRes = + assert.commandWorked(collection.explain().find(query, projection).sort(sort).finish()); return getPlanCacheKeyFromExplain(explainRes, db); } @@ -554,80 +545,3 @@ function flattenQueryPlanTree(winningPlan) { stages.reverse(); return stages; } - -/** - * Recursively checks if a javascript object contains a nested property key and returns the - value. - * Note, this only recurses into other objects, array elements are ignored. - * - * This helper function can be used for any optimizer. - */ -function getNestedProperty(object, key) { - if (typeof object !== "object") { - return null; - } - - for (const k in object) { - if (k == key) { - return object[k]; - } - - const result = getNestedProperty(object[k], key); - if (result) { - return result; - } - } - return null; -} - -/** - * Returns the output from a single shard if 'explain' was obtained from an unsharded collection; - * returns 'explain' as is otherwise. - * - * This helper function can be used for any optimizer. - */ -function getSingleNodeExplain(explain) { - if ("shards" in explain) { - const shards = explain.shards; - const shardNames = Object.keys(shards); - // There should only be one shard given that this function assumes that 'explain' was - // obtained from an unsharded collection. - assert.eq(shardNames.length, 1, explain); - return shards[shardNames[0]]; - } - return explain; -} - -/** - * Utility to return the 'queryPlanner' section of 'explain'. The input is the root of the - * explain output. - * - * This helper function can be used for any optimizer. - */ -function getQueryPlanner(explain) { - explain = getSingleNodeExplain(explain); - if ("queryPlanner" in explain) { - const qp = explain.queryPlanner; - // Sharded case. - if ("winningPlan" in qp && "shards" in qp.winningPlan) { - return qp.winningPlan.shards[0]; - } - return qp; - } - assert(explain.hasOwnProperty("stages"), explain); - const stage = explain.stages[0]; - assert(stage.hasOwnProperty("$cursor"), explain); - const cursorStage = stage.$cursor; - assert(cursorStage.hasOwnProperty("queryPlanner"), explain); - return cursorStage.queryPlanner; -} - -/** - * Recognizes the query engine used by the query (sbe/classic). - * - * This helper function can be used for any optimizer. - */ -function getEngine(explain) { - const queryPlanner = getQueryPlanner(explain); - return getNestedProperty(queryPlanner, "slotBasedPlan") ? "sbe" : "classic"; -} |
