diff options
author | David Hatch <david.hatch@mongodb.com> | 2016-06-07 14:49:26 -0400 |
---|---|---|
committer | David Hatch <david.hatch@mongodb.com> | 2016-06-10 16:00:57 -0400 |
commit | f3f756132c74c1b44696d30faf6ef806fc7de860 (patch) | |
tree | beded88ba6037d7075c26155b7940017ab4b0ddf /src/mongo/db/exec/count_scan.cpp | |
parent | f1d618ed1009cd9e1da721535555083f31aad66e (diff) | |
download | mongo-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.cpp | 32 |
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; |