diff options
author | Ian Boros <ian.boros@mongodb.com> | 2020-03-17 14:21:45 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-04-01 01:29:42 +0000 |
commit | 5557279e9ca9c78fbeb1026fc1a48a5c7c334b71 (patch) | |
tree | 786f50500c09991caed8ea9a2b72538abd4c6a77 /src/mongo/db/exec/document_value/document_internal.h | |
parent | 45da9589d4ea5929404e9674718927a6be352b4d (diff) | |
download | mongo-5557279e9ca9c78fbeb1026fc1a48a5c7c334b71.tar.gz |
SERVER-45763 optimize sort key generation
Diffstat (limited to 'src/mongo/db/exec/document_value/document_internal.h')
-rw-r--r-- | src/mongo/db/exec/document_value/document_internal.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mongo/db/exec/document_value/document_internal.h b/src/mongo/db/exec/document_value/document_internal.h index 5cd5d4692c4..d77ac6b5014 100644 --- a/src/mongo/db/exec/document_value/document_internal.h +++ b/src/mongo/db/exec/document_value/document_internal.h @@ -37,6 +37,7 @@ #include "mongo/base/static_assert.h" #include "mongo/db/exec/document_value/document_metadata_fields.h" #include "mongo/db/exec/document_value/value.h" +#include "mongo/stdx/variant.h" #include "mongo/util/intrusive_counter.h" namespace mongo { @@ -352,6 +353,26 @@ public: return getField(pos).val; } + /** + * Given a field name either return a Value if the field resides in the cache, or a BSONElement + * if the field resides in the backing BSON. + */ + stdx::variant<BSONElement, Value> getFieldNonCaching(StringData name) const { + Position pos = findField(name, LookupPolicy::kCacheOnly); + if (pos.found()) { + return {getField(pos).val}; + } + + for (auto&& bsonElement : _bson) { + if (name == bsonElement.fieldNameStringData()) { + return {bsonElement}; + } + } + + // Field not found. Return EOO Value. + return {Value()}; + } + /// Adds a new field with missing Value at the end of the document Value& appendField(StringData name, ValueElement::Kind kind); |