diff options
author | James Wahlin <james.wahlin@10gen.com> | 2016-01-05 12:16:42 -0500 |
---|---|---|
committer | James Wahlin <james.wahlin@10gen.com> | 2016-01-08 08:58:57 -0500 |
commit | 176fad1a68fd9d0750a3aa4b33c2eb20be7d39ec (patch) | |
tree | a0a335b326d254b9da486e7af4050d46ed72fbf1 | |
parent | 4846585c6a7f09a18ac8c313ca7b0cee405ad29c (diff) | |
download | mongo-176fad1a68fd9d0750a3aa4b33c2eb20be7d39ec.tar.gz |
SERVER-22048 Record index access stats for aggregation and mapReduce
-rw-r--r-- | jstests/core/index_stats.js | 17 | ||||
-rw-r--r-- | src/mongo/db/commands/mr.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/commands/pipeline_command.cpp | 10 |
3 files changed, 32 insertions, 0 deletions
diff --git a/jstests/core/index_stats.js b/jstests/core/index_stats.js index 5ef871bf2da..acf2951213b 100644 --- a/jstests/core/index_stats.js +++ b/jstests/core/index_stats.js @@ -88,6 +88,23 @@ countB++; assert.eq(countB, getUsageCount("b_1_c_1")); + // Confirm index stats tick on aggregate w/ match. + res = db.runCommand({aggregate: colName, + pipeline: [{$match: {b: 1}}]}); + assert.commandWorked(res); + countB++; + assert.eq(countB, getUsageCount("b_1_c_1")); + + // Confirm index stats tick on mapReduce with query. + res = db.runCommand({mapReduce: colName, + map: function() {emit(this.b, this.c);}, + reduce: function(key, val) {return val;}, + query: {b: 2}, + out: {inline: true}}); + assert.commandWorked(res); + countB++; + assert.eq(countB, getUsageCount("b_1_c_1")); + // Confirm index stats tick on update(). assert.writeOK(col.update({a: 2}, {$set: {d: 2}})); countA++; diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index d0066e7e066..27edf464286 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -1465,6 +1465,11 @@ public: if (config.limit && numInputs >= config.limit) break; } + + // Record the indexes used by the PlanExecutor. + PlanSummaryStats stats; + Explain::getSummaryStats(*exec, &stats); + coll->infoCache()->notifyOfQuery(txn, stats.indexesUsed); } pm.finished(); diff --git a/src/mongo/db/commands/pipeline_command.cpp b/src/mongo/db/commands/pipeline_command.cpp index ada7e33e311..f8bbf2fc81c 100644 --- a/src/mongo/db/commands/pipeline_command.cpp +++ b/src/mongo/db/commands/pipeline_command.cpp @@ -228,6 +228,16 @@ public: PipelineD::prepareCursorSource(txn, collection, pPipeline, pCtx); pPipeline->stitch(); + if (collection && input) { + // Record the indexes used by the input executor. Retrieval of summary stats for a + // PlanExecutor is normally done post execution. DocumentSourceCursor however will + // destroy the input PlanExecutor once the result set has been exhausted. For + // that reason we need to collect the indexes used prior to plan execution. + PlanSummaryStats stats; + Explain::getSummaryStats(*input, &stats); + collection->infoCache()->notifyOfQuery(txn, stats.indexesUsed); + } + // Create the PlanExecutor which returns results from the pipeline. The WorkingSet // ('ws') and the PipelineProxyStage ('proxy') will be owned by the created // PlanExecutor. |