summaryrefslogtreecommitdiff
path: root/src/mongo/db/exec/count_scan.cpp
diff options
context:
space:
mode:
authorDavid Hatch <david.hatch@mongodb.com>2016-06-07 14:49:26 -0400
committerDavid Hatch <david.hatch@mongodb.com>2016-06-10 16:00:57 -0400
commitf3f756132c74c1b44696d30faf6ef806fc7de860 (patch)
treebeded88ba6037d7075c26155b7940017ab4b0ddf /src/mongo/db/exec/count_scan.cpp
parentf1d618ed1009cd9e1da721535555083f31aad66e (diff)
downloadmongo-f3f756132c74c1b44696d30faf6ef806fc7de860.tar.gz
SERVER-23064 COUNT_SCAN query execution stage does not report index bounds in execution stats output for explain
Diffstat (limited to 'src/mongo/db/exec/count_scan.cpp')
-rw-r--r--src/mongo/db/exec/count_scan.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/db/exec/count_scan.cpp b/src/mongo/db/exec/count_scan.cpp
index 41f67e51d02..06a33c0fd15 100644
--- a/src/mongo/db/exec/count_scan.cpp
+++ b/src/mongo/db/exec/count_scan.cpp
@@ -35,6 +35,32 @@
namespace mongo {
+namespace {
+/**
+ * This function replaces field names in *replace* with those from the object
+ * *fieldNames*, preserving field ordering. Both objects must have the same
+ * number of fields.
+ *
+ * Example:
+ *
+ * replaceBSONKeyNames({ 'a': 1, 'b' : 1 }, { '': 'foo', '', 'bar' }) =>
+ *
+ * { 'a' : 'foo' }, { 'b' : 'bar' }
+ */
+BSONObj replaceBSONFieldNames(const BSONObj& replace, const BSONObj& fieldNames) {
+ invariant(replace.nFields() == fieldNames.nFields());
+
+ BSONObjBuilder bob;
+ BSONObjIterator iter = fieldNames.begin();
+
+ for (const BSONElement& el : replace) {
+ bob.appendAs(el, (*iter++).fieldNameStringData());
+ }
+
+ return bob.obj();
+}
+}
+
using std::unique_ptr;
using std::vector;
using stdx::make_unique;
@@ -160,6 +186,12 @@ unique_ptr<PlanStageStats> CountScan::getStats() {
unique_ptr<CountScanStats> countStats = make_unique<CountScanStats>(_specificStats);
countStats->keyPattern = _specificStats.keyPattern.getOwned();
+
+ countStats->startKey = replaceBSONFieldNames(_params.startKey, countStats->keyPattern);
+ countStats->startKeyInclusive = _params.startKeyInclusive;
+ countStats->endKey = replaceBSONFieldNames(_params.endKey, countStats->keyPattern);
+ countStats->endKeyInclusive = _params.endKeyInclusive;
+
ret->specific = std::move(countStats);
return ret;