diff options
author | Dan Larkin-York <dan.larkin-york@mongodb.com> | 2022-01-21 13:29:55 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-01-21 13:56:33 +0000 |
commit | e1edb466aaacbe0c9f62846765349d7d69ea8c8c (patch) | |
tree | 6faa64e547635e0f8e6beeb6d6c25911c0707d24 | |
parent | 5d23bc5c0ea914d5987ef46f8c9edb5b6e969ee2 (diff) | |
download | mongo-e1edb466aaacbe0c9f62846765349d7d69ea8c8c.tar.gz |
SERVER-62428 Avoid unnecessary copying while unpacking time-series buckets
-rw-r--r-- | src/mongo/db/exec/bucket_unpacker.cpp | 42 | ||||
-rw-r--r-- | src/mongo/db/exec/bucket_unpacker.h | 5 |
2 files changed, 23 insertions, 24 deletions
diff --git a/src/mongo/db/exec/bucket_unpacker.cpp b/src/mongo/db/exec/bucket_unpacker.cpp index 4c447bb6d9d..7f479ce763e 100644 --- a/src/mongo/db/exec/bucket_unpacker.cpp +++ b/src/mongo/db/exec/bucket_unpacker.cpp @@ -43,7 +43,7 @@ public: virtual int measurementCount(const BSONElement& timeField) const = 0; virtual bool getNext(MutableDocument& measurement, const BucketSpec& spec, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) = 0; virtual void extractSingleMeasurement(MutableDocument& measurement, @@ -51,7 +51,7 @@ public: const BucketSpec& spec, BucketUnpacker::Behavior behavior, const BSONObj& bucket, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) = 0; @@ -94,7 +94,7 @@ public: int measurementCount(const BSONElement& timeField) const override; bool getNext(MutableDocument& measurement, const BucketSpec& spec, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) override; void extractSingleMeasurement(MutableDocument& measurement, @@ -102,7 +102,7 @@ public: const BucketSpec& spec, BucketUnpacker::Behavior behavior, const BSONObj& bucket, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) override; std::size_t numberOfFields() override; @@ -158,7 +158,7 @@ int BucketUnpackerV1::measurementCount(const BSONElement& timeField) const { bool BucketUnpackerV1::getNext(MutableDocument& measurement, const BucketSpec& spec, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) { auto&& timeElem = _timeFieldIter.next(); @@ -167,8 +167,8 @@ bool BucketUnpackerV1::getNext(MutableDocument& measurement, } // Includes metaField when we're instructed to do so and metaField value exists. - if (includeMetaField && metaValue) { - measurement.addField(*spec.metaField, Value{metaValue}); + if (includeMetaField && !metaValue.missing()) { + measurement.addField(*spec.metaField, metaValue); } auto& currentIdx = timeElem.fieldNameStringData(); @@ -187,15 +187,15 @@ void BucketUnpackerV1::extractSingleMeasurement(MutableDocument& measurement, const BucketSpec& spec, BucketUnpacker::Behavior behavior, const BSONObj& bucket, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) { auto rowKey = std::to_string(j); auto targetIdx = StringData{rowKey}; auto&& dataRegion = bucket.getField(timeseries::kBucketDataFieldName).Obj(); - if (includeMetaField && !metaValue.isNull()) { - measurement.addField(*spec.metaField, Value{metaValue}); + if (includeMetaField && !metaValue.missing()) { + measurement.addField(*spec.metaField, metaValue); } for (auto&& dataElem : dataRegion) { @@ -225,7 +225,7 @@ public: int measurementCount(const BSONElement& timeField) const override; bool getNext(MutableDocument& measurement, const BucketSpec& spec, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) override; void extractSingleMeasurement(MutableDocument& measurement, @@ -233,7 +233,7 @@ public: const BucketSpec& spec, BucketUnpacker::Behavior behavior, const BSONObj& bucket, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) override; std::size_t numberOfFields() override; @@ -277,7 +277,7 @@ int BucketUnpackerV2::measurementCount(const BSONElement& timeField) const { bool BucketUnpackerV2::getNext(MutableDocument& measurement, const BucketSpec& spec, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) { // Get element and increment iterator @@ -288,8 +288,8 @@ bool BucketUnpackerV2::getNext(MutableDocument& measurement, ++_timeColumn.it; // Includes metaField when we're instructed to do so and metaField value exists. - if (includeMetaField && metaValue) { - measurement.addField(*spec.metaField, Value{metaValue}); + if (includeMetaField && !metaValue.missing()) { + measurement.addField(*spec.metaField, metaValue); } for (auto& fieldColumn : _fieldColumns) { @@ -312,7 +312,7 @@ void BucketUnpackerV2::extractSingleMeasurement(MutableDocument& measurement, const BucketSpec& spec, BucketUnpacker::Behavior behavior, const BSONObj& bucket, - const BSONElement& metaValue, + const Value& metaValue, bool includeTimeField, bool includeMetaField) { if (includeTimeField) { @@ -322,8 +322,8 @@ void BucketUnpackerV2::extractSingleMeasurement(MutableDocument& measurement, measurement.addField(_timeColumn.column.name(), Value{*val}); } - if (includeMetaField && !metaValue.isNull()) { - measurement.addField(*spec.metaField, Value{metaValue}); + if (includeMetaField && !metaValue.missing()) { + measurement.addField(*spec.metaField, metaValue); } if (includeTimeField) { @@ -442,7 +442,7 @@ void BucketUnpacker::reset(BSONObj&& bucket) { "The $_internalUnpackBucket stage requires the data region to have a timeField object", timeFieldElem); - _metaValue = _bucket[timeseries::kBucketMetaFieldName]; + _metaValue = Value{_bucket[timeseries::kBucketMetaFieldName]}; if (_spec.metaField) { // The spec indicates that there might be a metadata region. Missing metadata in // measurements is expressed with missing metadata in a bucket. But we disallow undefined @@ -450,14 +450,14 @@ void BucketUnpacker::reset(BSONObj&& bucket) { uassert(5369600, "The $_internalUnpackBucket stage allows metadata to be absent or otherwise, it " "must not be the deprecated undefined bson type", - !_metaValue || _metaValue.type() != BSONType::Undefined); + _metaValue.missing() || _metaValue.getType() != BSONType::Undefined); } else { // If the spec indicates that the time series collection has no metadata field, then we // should not find a metadata region in the underlying bucket documents. uassert(5369601, "The $_internalUnpackBucket stage expects buckets to have missing metadata regions " "if the metaField parameter is not provided", - !_metaValue); + _metaValue.missing()); } diff --git a/src/mongo/db/exec/bucket_unpacker.h b/src/mongo/db/exec/bucket_unpacker.h index 5499fed46c4..da057735691 100644 --- a/src/mongo/db/exec/bucket_unpacker.h +++ b/src/mongo/db/exec/bucket_unpacker.h @@ -167,10 +167,9 @@ private: BSONObj _bucket; // Since the metadata value is the same across all materialized measurements we can cache the - // metadata BSONElement in the reset phase and use it to materialize the metadata in each + // metadata Value in the reset phase and use it to materialize the metadata in each // measurement. - BSONElement _metaValue; - + Value _metaValue; // Map <name, BSONElement> for the computed meta field projections. Updated for // every bucket upon reset(). |