diff options
author | Hirday Gupta <hirday.gupta@mongodb.com> | 2020-06-24 16:49:07 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-06 23:54:22 +0000 |
commit | 2b01612eceb90dee3681e86ec2cea90229ed5fe3 (patch) | |
tree | 8e428db6ed5d64ccb4693aa7c45080ad19106837 | |
parent | 0b5bbf4cc0169ed2a527fe5c93d4adb09a9a5af3 (diff) | |
download | mongo-2b01612eceb90dee3681e86ec2cea90229ed5fe3.tar.gz |
SERVER-48244 remove shell-side explain string validation
(cherry picked from commit c76a5544eb4423c7dbca6862fddf9371ce999f6f)
-rw-r--r-- | jstests/core/explain_find.js | 76 | ||||
-rw-r--r-- | jstests/core/explain_shell_helpers.js | 8 | ||||
-rw-r--r-- | src/mongo/shell/explainable.js | 8 |
3 files changed, 47 insertions, 45 deletions
diff --git a/jstests/core/explain_find.js b/jstests/core/explain_find.js index 87174e99a62..cb74985ac87 100644 --- a/jstests/core/explain_find.js +++ b/jstests/core/explain_find.js @@ -1,32 +1,48 @@ // Tests for explaining find through the explain command. -var collName = "jstests_explain_find"; -var t = db[collName]; -t.drop(); - -t.ensureIndex({a: 1}); - -for (var i = 0; i < 10; i++) { - t.insert({_id: i, a: i}); -} - -var explain = - db.runCommand({explain: {find: collName, filter: {a: {$lte: 2}}}, verbosity: "executionStats"}); -printjson(explain); -assert.commandWorked(explain); -assert.eq(3, explain.executionStats.nReturned); - -explain = db.runCommand( - {explain: {find: collName, min: {a: 4}, max: {a: 6}}, verbosity: "executionStats"}); -printjson(explain); -assert.commandWorked(explain); -assert.eq(2, explain.executionStats.nReturned); - -// Compatibility test for the $explain OP_QUERY flag. This can only run if find command is disabled. -if (!db.getMongo().useReadCommands()) { - var explain = t.find({$query: {a: 4}, $explain: true}).limit(-1).next(); - assert("queryPlanner" in explain); - assert("executionStats" in explain); - assert.eq(1, explain.executionStats.nReturned); - assert("allPlansExecution" in explain.executionStats); -} +(function() { + "use strict"; + + var collName = "jstests_explain_find"; + var t = db[collName]; + t.drop(); + + t.ensureIndex({a: 1}); + + for (var i = 0; i < 10; i++) { + t.insert({_id: i, a: i}); + } + + var explain = db.runCommand( + {explain: {find: collName, filter: {a: {$lte: 2}}}, verbosity: "executionStats"}); + printjson(explain); + assert.commandWorked(explain); + assert.eq(3, explain.executionStats.nReturned); + + explain = db.runCommand( + {explain: {find: collName, min: {a: 4}, max: {a: 6}}, verbosity: "executionStats"}); + printjson(explain); + assert.commandWorked(explain); + assert.eq(2, explain.executionStats.nReturned); + + // Compatibility test for the $explain OP_QUERY flag. This can only run if find command is + // disabled. + if (!db.getMongo().useReadCommands()) { + var explain = t.find({$query: {a: 4}, $explain: true}).limit(-1).next(); + assert("queryPlanner" in explain); + assert("executionStats" in explain); + assert.eq(1, explain.executionStats.nReturned); + assert("allPlansExecution" in explain.executionStats); + } + + // Invalid verbosity string. + let error = assert.throws(function() { + t.explain("foobar").find().finish(); + }); + assert.commandFailedWithCode(error, ErrorCodes.FailedToParse); + + error = assert.throws(function() { + t.find().explain("foobar"); + }); + assert.commandFailedWithCode(error, ErrorCodes.FailedToParse); +}());
\ No newline at end of file diff --git a/jstests/core/explain_shell_helpers.js b/jstests/core/explain_shell_helpers.js index eb407be571b..4cc9ca3a0da 100644 --- a/jstests/core/explain_shell_helpers.js +++ b/jstests/core/explain_shell_helpers.js @@ -422,14 +422,6 @@ assert.eq(10, t.count()); // Error cases. // -// Invalid verbosity string. -assert.throws(function() { - t.explain("foobar").find().finish(); -}); -assert.throws(function() { - t.find().explain("foobar"); -}); - // Can't explain an update without a query. assert.throws(function() { t.explain().update(); diff --git a/src/mongo/shell/explainable.js b/src/mongo/shell/explainable.js index 795326ab9d0..da130b9b13c 100644 --- a/src/mongo/shell/explainable.js +++ b/src/mongo/shell/explainable.js @@ -4,7 +4,6 @@ // var Explainable = (function() { - var parseVerbosity = function(verbosity) { // Truthy non-strings are interpreted as "allPlansExecution" verbosity. if (verbosity && (typeof verbosity !== "string")) { @@ -16,12 +15,7 @@ var Explainable = (function() { return "queryPlanner"; } - // If we're here, then the verbosity is a string. We reject invalid strings. - if (verbosity !== "queryPlanner" && verbosity !== "executionStats" && - verbosity !== "allPlansExecution") { - throw Error("explain verbosity must be one of {" + "'queryPlanner'," + - "'executionStats'," + "'allPlansExecution'}"); - } + // All verbosity strings are passed through. Server validates if it is a known option. return verbosity; }; |