From 8e9a8b5552ae078e1890ec319909b7268adcfaac Mon Sep 17 00:00:00 2001 From: James Wahlin Date: Thu, 31 Oct 2019 13:21:47 +0000 Subject: SERVER-44013 MR Agg: Report plan stats and summary for currentOp/profiler/slow query logging --- jstests/core/profile_agg.js | 57 +++++++++++++++++++++++++++------------ jstests/core/profile_mapreduce.js | 28 +++++++++---------- 2 files changed, 53 insertions(+), 32 deletions(-) (limited to 'jstests/core') diff --git a/jstests/core/profile_agg.js b/jstests/core/profile_agg.js index 0b67296d9c0..d8e96d46646 100644 --- a/jstests/core/profile_agg.js +++ b/jstests/core/profile_agg.js @@ -8,26 +8,25 @@ // For getLatestProfilerEntry and getProfilerProtocolStringForCommand load("jstests/libs/profiler.js"); -var testDB = db.getSiblingDB("profile_agg"); +const testDB = db.getSiblingDB("profile_agg"); assert.commandWorked(testDB.dropDatabase()); -var coll = testDB.getCollection("test"); +const coll = testDB.getCollection("test"); testDB.setProfilingLevel(2); // // Confirm metrics for agg w/ $match. // -var i; -for (i = 0; i < 10; ++i) { +for (let i = 0; i < 10; ++i) { assert.commandWorked(coll.insert({a: i})); } assert.commandWorked(coll.createIndex({a: 1})); -assert.eq( - 8, - coll.aggregate([{$match: {a: {$gte: 2}}}], {collation: {locale: "fr"}, comment: "agg_comment"}) - .itcount()); -var profileObj = getLatestProfilerEntry(testDB); +assert.eq(8, + coll.aggregate([{$match: {a: {$gte: 2}}}, {$sort: {b: 1}}, {$addFields: {c: 1}}], + {collation: {locale: "fr"}, comment: "agg_comment"}) + .itcount()); +let profileObj = getLatestProfilerEntry(testDB); assert.eq(profileObj.ns, coll.getFullName(), tojson(profileObj)); assert.eq(profileObj.op, "command", tojson(profileObj)); @@ -45,38 +44,60 @@ assert(profileObj.hasOwnProperty("responseLength"), tojson(profileObj)); assert(profileObj.hasOwnProperty("millis"), tojson(profileObj)); assert(profileObj.hasOwnProperty("numYield"), tojson(profileObj)); assert(profileObj.hasOwnProperty("locks"), tojson(profileObj)); -assert(!profileObj.hasOwnProperty("hasSortStage"), tojson(profileObj)); +assert(profileObj.hasOwnProperty("hasSortStage"), tojson(profileObj)); // Testing that 'usedDisk' is set when disk is used requires either using a lot of data or // configuring a server parameter which could mess up other tests. This testing is // done elsewhere so that this test can stay in the core suite assert(!profileObj.hasOwnProperty("usedDisk"), tojson(profileObj)); assert.eq(profileObj.appName, "MongoDB Shell", tojson(profileObj)); +// Confirm that 'hasSortStage' is not present when the sort is non-blocking. +coll.aggregate([{$match: {a: {$gte: 2}}}, {$sort: {a: 1}}, {$addFields: {c: 1}}], + {collation: {locale: "fr"}, comment: "agg_comment"}); +profileObj = getLatestProfilerEntry(testDB); +assert(!profileObj.hasOwnProperty("hasSortStage"), tojson(profileObj)); + // // Confirm "fromMultiPlanner" metric. // -coll.drop(); +assert(coll.drop()); assert.commandWorked(coll.createIndex({a: 1})); assert.commandWorked(coll.createIndex({b: 1})); -for (i = 0; i < 5; ++i) { +for (let i = 0; i < 5; ++i) { assert.commandWorked(coll.insert({a: i, b: i})); } -assert.eq(1, coll.aggregate([{$match: {a: 3, b: 3}}]).itcount()); +assert.eq(1, coll.aggregate([{$match: {a: 3, b: 3}}, {$addFields: {c: 1}}]).itcount()); profileObj = getLatestProfilerEntry(testDB); assert.eq(profileObj.fromMultiPlanner, true, tojson(profileObj)); +// +// Confirm that the correct namespace is written to the profiler when running an aggregation with a +// $out stage. +// +assert(coll.drop()); +db.profile_agg_out.drop(); +for (let i = 0; i < 5; ++i) { + assert.commandWorked(coll.insert({a: i})); +} + +assert.eq(0, coll.aggregate([{$match: {a: {$gt: 0}}}, {$out: "profile_agg_out"}]).itcount()); +profileObj = getLatestProfilerEntry(testDB); + +assert.eq(profileObj.ns, coll.getFullName(), tojson(profileObj)); + // // Confirm that the "hint" modifier is in the profiler document. // -coll.drop(); +assert(coll.drop()); assert.commandWorked(coll.createIndex({a: 1})); -for (i = 0; i < 5; ++i) { +for (let i = 0; i < 5; ++i) { assert.commandWorked(coll.insert({a: i, b: i})); } -assert.eq(1, coll.aggregate([{$match: {a: 3, b: 3}}], {hint: {_id: 1}}).itcount()); +assert.eq( + 1, coll.aggregate([{$match: {a: 3, b: 3}}, {$addFields: {c: 1}}], {hint: {_id: 1}}).itcount()); profileObj = getLatestProfilerEntry(testDB); assert.eq(profileObj.command.hint, {_id: 1}, tojson(profileObj)); @@ -90,7 +111,9 @@ for (let i = 0; i < 501; i++) { matchPredicate[i] = "a".repeat(150); } -assert.eq(coll.aggregate([{$match: matchPredicate}], {comment: "profile_agg"}).itcount(), 0); +assert.eq(coll.aggregate([{$match: matchPredicate}, {$addFields: {c: 1}}], {comment: "profile_agg"}) + .itcount(), + 0); profileObj = getLatestProfilerEntry(testDB); assert.eq((typeof profileObj.command.$truncated), "string", tojson(profileObj)); assert.eq(profileObj.command.comment, "profile_agg", tojson(profileObj)); diff --git a/jstests/core/profile_mapreduce.js b/jstests/core/profile_mapreduce.js index 00a52871bd9..608971f8684 100644 --- a/jstests/core/profile_mapreduce.js +++ b/jstests/core/profile_mapreduce.js @@ -14,26 +14,25 @@ // For getLatestProfilerEntry and getProfilerProtocolStringForCommand load("jstests/libs/profiler.js"); -var testDB = db.getSiblingDB("profile_mapreduce"); +const testDB = db.getSiblingDB("profile_mapreduce"); assert.commandWorked(testDB.dropDatabase()); -var conn = testDB.getMongo(); -var coll = testDB.getCollection("test"); +const conn = testDB.getMongo(); +const coll = testDB.getCollection("test"); testDB.setProfilingLevel(2); -var mapFunction = function() { +const mapFunction = function() { emit(this.a, this.b); }; -var reduceFunction = function(a, b) { +const reduceFunction = function(a, b) { return Array.sum(b); }; // // Confirm metrics for mapReduce with query. // -coll.drop(); -for (var i = 0; i < 3; i++) { +for (let i = 0; i < 3; i++) { assert.commandWorked(coll.insert({a: i, b: i})); } assert.commandWorked(coll.createIndex({a: 1})); @@ -42,14 +41,13 @@ coll.mapReduce(mapFunction, reduceFunction, {query: {a: {$gte: 0}}, out: {inline: 1}, collation: {locale: "fr"}}); -var profileObj = getLatestProfilerEntry(testDB); +let profileObj = getLatestProfilerEntry(testDB); assert.eq(profileObj.ns, coll.getFullName(), tojson(profileObj)); assert.eq(profileObj.op, "command", tojson(profileObj)); assert.eq(profileObj.keysExamined, 3, tojson(profileObj)); assert.eq(profileObj.docsExamined, 3, tojson(profileObj)); assert.eq(profileObj.planSummary, "IXSCAN { a: 1 }", tojson(profileObj)); -assert(profileObj.execStats.hasOwnProperty("stage"), tojson(profileObj)); assert.eq(profileObj.protocol, getProfilerProtocolStringForCommand(conn), tojson(profileObj)); assert.eq(coll.getName(), profileObj.command.mapreduce, tojson(profileObj)); assert.eq({locale: "fr"}, profileObj.command.collation, tojson(profileObj)); @@ -62,8 +60,8 @@ assert.eq(profileObj.appName, "MongoDB Shell", tojson(profileObj)); // // Confirm metrics for mapReduce with sort stage. // -coll.drop(); -for (var i = 0; i < 5; i++) { +assert(coll.drop()); +for (let i = 0; i < 5; i++) { assert.commandWorked(coll.insert({a: i, b: i})); } @@ -76,8 +74,8 @@ assert.eq(profileObj.appName, "MongoDB Shell", tojson(profileObj)); // // Confirm namespace field is correct when output is a collection. // -coll.drop(); -for (var i = 0; i < 3; i++) { +assert(coll.drop()); +for (let i = 0; i < 3; i++) { assert.commandWorked(coll.insert({a: i, b: i})); } @@ -90,10 +88,10 @@ assert.eq(profileObj.ns, coll.getFullName(), tojson(profileObj)); // // Confirm "fromMultiPlanner" metric. // -coll.drop(); +assert(coll.drop()); assert.commandWorked(coll.createIndex({a: 1})); assert.commandWorked(coll.createIndex({b: 1})); -for (i = 0; i < 5; ++i) { +for (let i = 0; i < 5; ++i) { assert.commandWorked(coll.insert({a: i, b: i})); } -- cgit v1.2.1