From e5e2ecb49da979c5cc3534ae3cb76212a72e3986 Mon Sep 17 00:00:00 2001 From: James Wahlin Date: Thu, 14 Jul 2016 14:58:56 -0400 Subject: SERVER-17275 Remove 'stats' field from distinct command response --- jstests/core/distinct1.js | 2 -- jstests/core/distinct_index1.js | 47 ++++++++++++++++++++------------------ src/mongo/db/commands/distinct.cpp | 13 ----------- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/jstests/core/distinct1.js b/jstests/core/distinct1.js index 893e1f6ba65..a70d027e51b 100644 --- a/jstests/core/distinct1.js +++ b/jstests/core/distinct1.js @@ -24,8 +24,6 @@ t.save({a: {b: "c"}, c: 12}); res = t.distinct("a.b"); assert.eq("a,b,c", res.toString(), "B1"); -printjson(t._distinct("a.b").stats); -assert.eq("COLLSCAN", t._distinct("a.b").stats.planSummary, "B2"); t.drop(); diff --git a/jstests/core/distinct_index1.js b/jstests/core/distinct_index1.js index 026fdca4e0a..b9dd3553a55 100644 --- a/jstests/core/distinct_index1.js +++ b/jstests/core/distinct_index1.js @@ -2,12 +2,14 @@ t = db.distinct_index1; t.drop(); +load("jstests/libs/analyze_plan.js"); + function r(x) { return Math.floor(Math.sqrt(x * 123123)) % 10; } function d(k, q) { - return t.runCommand("distinct", {key: k, query: q || {}}); + return t.explain("executionStats").distinct(k, q || {}); } for (i = 0; i < 1000; i++) { @@ -18,42 +20,42 @@ for (i = 0; i < 1000; i++) { x = d("a"); // Collection scan looks at all 1000 documents and gets 1000 // distinct values. Looks at 0 index keys. -assert.eq(1000, x.stats.n, "AA1"); -assert.eq(0, x.stats.nscanned, "AA2"); -assert.eq(1000, x.stats.nscannedObjects, "AA3"); +assert.eq(1000, x.executionStats.nReturned, "AA1"); +assert.eq(0, x.executionStats.totalKeysExamined, "AA2"); +assert.eq(1000, x.executionStats.totalDocsExamined, "AA3"); x = d("a", {a: {$gt: 5}}); // Collection scan looks at all 1000 documents and gets 398 // distinct values which match the query. Looks at 0 index keys. -assert.eq(398, x.stats.n, "AB1"); -assert.eq(0, x.stats.nscanned, "AB2"); -assert.eq(1000, x.stats.nscannedObjects, "AB3"); +assert.eq(398, x.executionStats.nReturned, "AB1"); +assert.eq(0, x.executionStats.totalKeysExamined, "AB2"); +assert.eq(1000, x.executionStats.totalDocsExamined, "AB3"); x = d("b", {a: {$gt: 5}}); // Collection scan looks at all 1000 documents and gets 398 // distinct values which match the query. Looks at 0 index keys. -assert.eq(398, x.stats.n, "AC1"); -assert.eq(0, x.stats.nscanned, "AC2"); -assert.eq(1000, x.stats.nscannedObjects, "AC3"); +assert.eq(398, x.executionStats.nReturned, "AC1"); +assert.eq(0, x.executionStats.totalKeysExamined, "AC2"); +assert.eq(1000, x.executionStats.totalDocsExamined, "AC3"); t.ensureIndex({a: 1}); x = d("a"); // There are only 10 values. We use the fast distinct hack and only examine each value once. -assert.eq(10, x.stats.n, "BA1"); -assert.eq(10, x.stats.nscanned, "BA2"); +assert.eq(10, x.executionStats.nReturned, "BA1"); +assert.eq(10, x.executionStats.totalKeysExamined, "BA2"); x = d("a", {a: {$gt: 5}}); // Only 4 values of a are >= 5 and we use the fast distinct hack. -assert.eq(4, x.stats.n, "BB1"); -assert.eq(4, x.stats.nscanned, "BB2"); -assert.eq(0, x.stats.nscannedObjects, "BB3"); +assert.eq(4, x.executionStats.nReturned, "BB1"); +assert.eq(4, x.executionStats.totalKeysExamined, "BB2"); +assert.eq(0, x.executionStats.totalDocsExamined, "BB3"); x = d("b", {a: {$gt: 5}}); // We can't use the fast distinct hack here because we're distinct-ing over 'b'. -assert.eq(398, x.stats.n, "BC1"); -assert.eq(398, x.stats.nscanned, "BC2"); -assert.eq(398, x.stats.nscannedObjects, "BC3"); +assert.eq(398, x.executionStats.nReturned, "BC1"); +assert.eq(398, x.executionStats.totalKeysExamined, "BC2"); +assert.eq(398, x.executionStats.totalDocsExamined, "BC3"); // Check proper nscannedObjects count when using a query optimizer cursor. t.dropIndexes(); @@ -62,12 +64,13 @@ x = d("b", {a: {$gt: 5}, b: {$gt: 5}}); printjson(x); // 171 is the # of results we happen to scan when we don't use a distinct // hack. When we use the distinct hack we scan 16, currently. -assert.lte(x.stats.n, 171); -assert.eq(171, x.stats.nscannedObjects, "BD3"); +assert.lte(x.executionStats.nReturned, 171); +assert.eq(171, x.executionStats.totalDocsExamined, "BD3"); // Should use an index scan over the hashed index. t.dropIndexes(); t.ensureIndex({a: "hashed"}); x = d("a", {$or: [{a: 3}, {a: 5}]}); -assert.eq(188, x.stats.n, "DA1"); -assert.eq("IXSCAN { a: \"hashed\" }", x.stats.planSummary); +assert.eq(188, x.executionStats.nReturned, "DA1"); +var indexScanStage = getPlanStage(x.executionStats.executionStages, "IXSCAN"); +assert.eq("hashed", indexScanStage.keyPattern.a); diff --git a/src/mongo/db/commands/distinct.cpp b/src/mongo/db/commands/distinct.cpp index e66f29779b1..1d5dc89a24f 100644 --- a/src/mongo/db/commands/distinct.cpp +++ b/src/mongo/db/commands/distinct.cpp @@ -56,7 +56,6 @@ #include "mongo/db/query/query_planner_common.h" #include "mongo/stdx/memory.h" #include "mongo/util/log.h" -#include "mongo/util/timer.h" namespace mongo { @@ -141,8 +140,6 @@ public: int, string& errmsg, BSONObjBuilder& result) { - Timer t; - const string ns = parseNs(dbname, cmdObj); const NamespaceString nss(ns); @@ -239,16 +236,6 @@ public: result.appendArray("values", arr.done()); - { - BSONObjBuilder b; - b.appendNumber("n", stats.nReturned); - b.appendNumber("nscanned", stats.totalKeysExamined); - b.appendNumber("nscannedObjects", stats.totalDocsExamined); - b.appendNumber("timems", t.millis()); - b.append("planSummary", Explain::getPlanSummary(executor.getValue().get())); - result.append("stats", b.obj()); - } - return true; } } distinctCmd; -- cgit v1.2.1