summaryrefslogtreecommitdiff
path: root/src/mongo/db/index
diff options
context:
space:
mode:
authorJordi Olivares Provencio <jordi.olivares-provencio@mongodb.com>2022-07-15 14:46:25 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-15 16:26:15 +0000
commitd8616301f12951868e52e19cd696cff620caa28e (patch)
tree8e3ddeddae9ba83be8899c93cbfa465fda7e20a9 /src/mongo/db/index
parent6af105aa73b7e3ed88186a14a5e832434af65863 (diff)
downloadmongo-d8616301f12951868e52e19cd696cff620caa28e.tar.gz
SERVER-67471 Improve RecordId usage performance
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r--src/mongo/db/index/2d_access_method.cpp2
-rw-r--r--src/mongo/db/index/2d_access_method.h2
-rw-r--r--src/mongo/db/index/btree_access_method.cpp2
-rw-r--r--src/mongo/db/index/btree_access_method.h2
-rw-r--r--src/mongo/db/index/btree_key_generator.cpp8
-rw-r--r--src/mongo/db/index/btree_key_generator.h8
-rw-r--r--src/mongo/db/index/column_store_sorter.cpp4
-rw-r--r--src/mongo/db/index/column_store_sorter.h2
-rw-r--r--src/mongo/db/index/expression_keys_private.cpp8
-rw-r--r--src/mongo/db/index/expression_keys_private.h8
-rw-r--r--src/mongo/db/index/fts_access_method.cpp2
-rw-r--r--src/mongo/db/index/fts_access_method.h2
-rw-r--r--src/mongo/db/index/hash_access_method.cpp2
-rw-r--r--src/mongo/db/index/hash_access_method.h2
-rw-r--r--src/mongo/db/index/index_access_method.cpp6
-rw-r--r--src/mongo/db/index/index_access_method.h8
-rw-r--r--src/mongo/db/index/index_build_interceptor.cpp4
-rw-r--r--src/mongo/db/index/s2_access_method.cpp2
-rw-r--r--src/mongo/db/index/s2_access_method.h2
-rw-r--r--src/mongo/db/index/s2_bucket_access_method.cpp2
-rw-r--r--src/mongo/db/index/s2_bucket_access_method.h2
-rw-r--r--src/mongo/db/index/wildcard_access_method.cpp2
-rw-r--r--src/mongo/db/index/wildcard_access_method.h2
-rw-r--r--src/mongo/db/index/wildcard_key_generator.cpp10
-rw-r--r--src/mongo/db/index/wildcard_key_generator.h10
25 files changed, 52 insertions, 52 deletions
diff --git a/src/mongo/db/index/2d_access_method.cpp b/src/mongo/db/index/2d_access_method.cpp
index d81a9f6ea30..d5af3a86a97 100644
--- a/src/mongo/db/index/2d_access_method.cpp
+++ b/src/mongo/db/index/2d_access_method.cpp
@@ -64,7 +64,7 @@ void TwoDAccessMethod::doGetKeys(OperationContext* opCtx,
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
ExpressionKeysPrivate::get2DKeys(pooledBufferBuilder,
obj,
_params,
diff --git a/src/mongo/db/index/2d_access_method.h b/src/mongo/db/index/2d_access_method.h
index e9621fcc7a2..a7ae364b994 100644
--- a/src/mongo/db/index/2d_access_method.h
+++ b/src/mongo/db/index/2d_access_method.h
@@ -70,7 +70,7 @@ private:
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const final;
+ const boost::optional<RecordId>& id) const final;
TwoDIndexingParams _params;
};
diff --git a/src/mongo/db/index/btree_access_method.cpp b/src/mongo/db/index/btree_access_method.cpp
index 177f03ad34b..71c9bf86fec 100644
--- a/src/mongo/db/index/btree_access_method.cpp
+++ b/src/mongo/db/index/btree_access_method.cpp
@@ -79,7 +79,7 @@ void BtreeAccessMethod::doGetKeys(OperationContext* opCtx,
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
const auto skipMultikey = context == GetKeysContext::kValidatingKeys &&
!_descriptor->getEntry()->isMultikey(opCtx, collection);
_keyGenerator->getKeys(pooledBufferBuilder,
diff --git a/src/mongo/db/index/btree_access_method.h b/src/mongo/db/index/btree_access_method.h
index 8f0e6304d20..5621c99933f 100644
--- a/src/mongo/db/index/btree_access_method.h
+++ b/src/mongo/db/index/btree_access_method.h
@@ -60,7 +60,7 @@ private:
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const final;
+ const boost::optional<RecordId>& id) const final;
// Our keys differ for V0 and V1.
std::unique_ptr<BtreeKeyGenerator> _keyGenerator;
diff --git a/src/mongo/db/index/btree_key_generator.cpp b/src/mongo/db/index/btree_key_generator.cpp
index f386a3aba87..b845aa2af1a 100644
--- a/src/mongo/db/index/btree_key_generator.cpp
+++ b/src/mongo/db/index/btree_key_generator.cpp
@@ -173,7 +173,7 @@ void BtreeKeyGenerator::_getKeysArrEltFixed(const std::vector<const char*>& fiel
const std::vector<PositionalPathInfo>& positionalInfo,
MultikeyPaths* multikeyPaths,
const CollatorInterface* collator,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
// fieldNamesTemp and fixedTemp are passed in by the caller to be used as temporary data
// structures as we need them to be mutable in the recursion. When they are stored outside we
// can reuse their memory.
@@ -210,7 +210,7 @@ void BtreeKeyGenerator::getKeys(SharedBufferFragmentBuilder& pooledBufferBuilder
KeyStringSet* keys,
MultikeyPaths* multikeyPaths,
const CollatorInterface* collator,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
if (_isIdIndex) {
// we special case for speed
BSONElement e = obj["_id"];
@@ -311,7 +311,7 @@ size_t BtreeKeyGenerator::PositionalPathInfo::getApproximateSize() const {
void BtreeKeyGenerator::_getKeysWithoutArray(SharedBufferFragmentBuilder& pooledBufferBuilder,
const BSONObj& obj,
const CollatorInterface* collator,
- boost::optional<RecordId> id,
+ const boost::optional<RecordId>& id,
KeyStringSet* keys) const {
KeyString::PooledBuilder keyString{pooledBufferBuilder, _keyStringVersion, _ordering};
@@ -351,7 +351,7 @@ void BtreeKeyGenerator::_getKeysWithArray(std::vector<const char*>* fieldNames,
const std::vector<PositionalPathInfo>& positionalInfo,
MultikeyPaths* multikeyPaths,
const CollatorInterface* collator,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
BSONElement arrElt;
// A set containing the position of any indexed fields in the key pattern that traverse through
diff --git a/src/mongo/db/index/btree_key_generator.h b/src/mongo/db/index/btree_key_generator.h
index 7287b68420d..36a5146f80c 100644
--- a/src/mongo/db/index/btree_key_generator.h
+++ b/src/mongo/db/index/btree_key_generator.h
@@ -84,7 +84,7 @@ public:
KeyStringSet* keys,
MultikeyPaths* multikeyPaths,
const CollatorInterface* collator = nullptr,
- boost::optional<RecordId> id = boost::none) const;
+ const boost::optional<RecordId>& id = boost::none) const;
size_t getApproximateSize() const;
@@ -157,7 +157,7 @@ private:
const std::vector<PositionalPathInfo>& positionalInfo,
MultikeyPaths* multikeyPaths,
const CollatorInterface* collator,
- boost::optional<RecordId> id) const;
+ const boost::optional<RecordId>& id) const;
/**
* An optimized version of the key generation algorithm to be used when it is known that 'obj'
@@ -166,7 +166,7 @@ private:
void _getKeysWithoutArray(SharedBufferFragmentBuilder& pooledBufferBuilder,
const BSONObj& obj,
const CollatorInterface* collator,
- boost::optional<RecordId> id,
+ const boost::optional<RecordId>& id,
KeyStringSet* keys) const;
/**
@@ -228,7 +228,7 @@ private:
const std::vector<PositionalPathInfo>& positionalInfo,
MultikeyPaths* multikeyPaths,
const CollatorInterface* collator,
- boost::optional<RecordId> id) const;
+ const boost::optional<RecordId>& id) const;
KeyString::Value _buildNullKeyString() const;
diff --git a/src/mongo/db/index/column_store_sorter.cpp b/src/mongo/db/index/column_store_sorter.cpp
index f708518a560..ef82ad9bf13 100644
--- a/src/mongo/db/index/column_store_sorter.cpp
+++ b/src/mongo/db/index/column_store_sorter.cpp
@@ -82,7 +82,7 @@ ColumnStoreSorter::ColumnStoreSorter(size_t maxMemoryUsageBytes,
_maxMemoryUsageBytes(maxMemoryUsageBytes),
_spillFile(std::make_shared<Sorter<Key, Value>::File>(pathForNewSpillFile(), _stats)) {}
-void ColumnStoreSorter::add(PathView path, RecordId recordId, CellView cellContents) {
+void ColumnStoreSorter::add(PathView path, const RecordId& recordId, CellView cellContents) {
auto& cellListAtPath = _dataByPath[path];
if (cellListAtPath.empty()) {
// Track memory usage of this new path.
@@ -181,7 +181,7 @@ void ColumnStoreSorter::spill() {
writer.writeChunk();
currentChunkSize = 0;
}
- for (auto ridAndCell : cellVector) {
+ for (auto& ridAndCell : cellVector) {
const auto& cell = ridAndCell.second;
currentChunkSize += path.size() + ridAndCell.first.memUsage() + cell.size();
writer.addAlreadySorted(Key{path, ridAndCell.first},
diff --git a/src/mongo/db/index/column_store_sorter.h b/src/mongo/db/index/column_store_sorter.h
index 833213b3646..56f203c5f64 100644
--- a/src/mongo/db/index/column_store_sorter.h
+++ b/src/mongo/db/index/column_store_sorter.h
@@ -54,7 +54,7 @@ class ColumnStoreSorter {
public:
ColumnStoreSorter(size_t maxMemoryUsageBytes, StringData dbName, SorterFileStats* stats);
- void add(PathView path, RecordId recordId, CellView cellContents);
+ void add(PathView path, const RecordId& recordId, CellView cellContents);
size_t numSpills() const {
return _numSpills;
diff --git a/src/mongo/db/index/expression_keys_private.cpp b/src/mongo/db/index/expression_keys_private.cpp
index 0e8fb0d6208..5463cc9de8d 100644
--- a/src/mongo/db/index/expression_keys_private.cpp
+++ b/src/mongo/db/index/expression_keys_private.cpp
@@ -489,7 +489,7 @@ void ExpressionKeysPrivate::get2DKeys(SharedBufferFragmentBuilder& pooledBufferB
KeyStringSet* keys,
KeyString::Version keyStringVersion,
Ordering ordering,
- boost::optional<RecordId> id) {
+ const boost::optional<RecordId>& id) {
BSONElementMultiSet bSet;
// Get all the nested location fields, but don't return individual elements from
@@ -581,7 +581,7 @@ void ExpressionKeysPrivate::getFTSKeys(SharedBufferFragmentBuilder& pooledBuffer
KeyStringSet* keys,
KeyString::Version keyStringVersion,
Ordering ordering,
- boost::optional<RecordId> id) {
+ const boost::optional<RecordId>& id) {
fts::FTSIndexFormat::getKeys(
pooledBufferBuilder, ftsSpec, obj, keys, keyStringVersion, ordering, id);
}
@@ -598,7 +598,7 @@ void ExpressionKeysPrivate::getHashKeys(SharedBufferFragmentBuilder& pooledBuffe
KeyString::Version keyStringVersion,
Ordering ordering,
bool ignoreArraysAlongPath,
- boost::optional<RecordId> id) {
+ const boost::optional<RecordId>& id) {
static const BSONObj nullObj = BSON("" << BSONNULL);
auto hasFieldValue = false;
KeyString::PooledBuilder keyString(pooledBufferBuilder, keyStringVersion, ordering);
@@ -672,7 +672,7 @@ void ExpressionKeysPrivate::getS2Keys(SharedBufferFragmentBuilder& pooledBufferB
KeyString::Version keyStringVersion,
SortedDataIndexAccessMethod::GetKeysContext context,
Ordering ordering,
- boost::optional<RecordId> id) {
+ const boost::optional<RecordId>& id) {
std::vector<KeyString::HeapBuilder> keysToAdd;
// Does one of our documents have a geo field?
diff --git a/src/mongo/db/index/expression_keys_private.h b/src/mongo/db/index/expression_keys_private.h
index dae982831ef..c97d48913c9 100644
--- a/src/mongo/db/index/expression_keys_private.h
+++ b/src/mongo/db/index/expression_keys_private.h
@@ -76,7 +76,7 @@ public:
KeyStringSet* keys,
KeyString::Version keyStringVersion,
Ordering ordering,
- boost::optional<RecordId> id = boost::none);
+ const boost::optional<RecordId>& id = boost::none);
//
// FTS
@@ -88,7 +88,7 @@ public:
KeyStringSet* keys,
KeyString::Version keyStringVersion,
Ordering ordering,
- boost::optional<RecordId> id = boost::none);
+ const boost::optional<RecordId>& id = boost::none);
//
// Hash
@@ -108,7 +108,7 @@ public:
KeyString::Version keyStringVersion,
Ordering ordering,
bool ignoreArraysAlongPath,
- boost::optional<RecordId> id = boost::none);
+ const boost::optional<RecordId>& id = boost::none);
/**
* Hashing function used by both getHashKeys and the cursors we create.
@@ -133,7 +133,7 @@ public:
KeyString::Version keyStringVersion,
SortedDataIndexAccessMethod::GetKeysContext context,
Ordering ordering,
- boost::optional<RecordId> id = boost::none);
+ const boost::optional<RecordId>& id = boost::none);
};
} // namespace mongo
diff --git a/src/mongo/db/index/fts_access_method.cpp b/src/mongo/db/index/fts_access_method.cpp
index 4fbda54dae9..78f2d68b21e 100644
--- a/src/mongo/db/index/fts_access_method.cpp
+++ b/src/mongo/db/index/fts_access_method.cpp
@@ -47,7 +47,7 @@ void FTSAccessMethod::doGetKeys(OperationContext* opCtx,
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
ExpressionKeysPrivate::getFTSKeys(pooledBufferBuilder,
obj,
_ftsSpec,
diff --git a/src/mongo/db/index/fts_access_method.h b/src/mongo/db/index/fts_access_method.h
index a1343553916..966b959af6a 100644
--- a/src/mongo/db/index/fts_access_method.h
+++ b/src/mongo/db/index/fts_access_method.h
@@ -60,7 +60,7 @@ private:
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const final;
+ const boost::optional<RecordId>& id) const final;
fts::FTSSpec _ftsSpec;
};
diff --git a/src/mongo/db/index/hash_access_method.cpp b/src/mongo/db/index/hash_access_method.cpp
index ec7b05b3665..7e7e7862fd3 100644
--- a/src/mongo/db/index/hash_access_method.cpp
+++ b/src/mongo/db/index/hash_access_method.cpp
@@ -63,7 +63,7 @@ void HashAccessMethod::doGetKeys(OperationContext* opCtx,
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
ExpressionKeysPrivate::getHashKeys(pooledBufferBuilder,
obj,
_keyPattern,
diff --git a/src/mongo/db/index/hash_access_method.h b/src/mongo/db/index/hash_access_method.h
index 851c841dbe2..6dc7df9e48d 100644
--- a/src/mongo/db/index/hash_access_method.h
+++ b/src/mongo/db/index/hash_access_method.h
@@ -67,7 +67,7 @@ private:
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const final;
+ const boost::optional<RecordId>& id) const final;
BSONObj _keyPattern;
diff --git a/src/mongo/db/index/index_access_method.cpp b/src/mongo/db/index/index_access_method.cpp
index 0144e00d973..f9cd8f7c7c2 100644
--- a/src/mongo/db/index/index_access_method.cpp
+++ b/src/mongo/db/index/index_access_method.cpp
@@ -437,7 +437,7 @@ RecordId SortedDataIndexAccessMethod::findSingle(OperationContext* opCtx,
if (auto loc = _newInterface->findLoc(opCtx, actualKey)) {
dassert(!loc->isNull());
- return *loc;
+ return std::move(*loc);
}
return RecordId();
@@ -771,7 +771,7 @@ Status SortedDataIndexAccessMethod::BulkBuilderImpl::insert(
&_multikeyMetadataKeys,
multikeyPaths.get(),
loc,
- [&](Status status, const BSONObj&, boost::optional<RecordId>) {
+ [&](Status status, const BSONObj&, const boost::optional<RecordId>&) {
// If a key generation error was suppressed, record the document as
// "skipped" so the index builder can retry at a point when data is
// consistent.
@@ -1018,7 +1018,7 @@ void SortedDataIndexAccessMethod::getKeys(OperationContext* opCtx,
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id,
+ const boost::optional<RecordId>& id,
OnSuppressedErrorFn&& onSuppressedError) const {
invariant(!id || _newInterface->rsKeyFormat() != KeyFormat::String || id->isStr(),
fmt::format("RecordId is not in the same string format as its RecordStore; id: {}",
diff --git a/src/mongo/db/index/index_access_method.h b/src/mongo/db/index/index_access_method.h
index 7e3a4dd504a..5136faed942 100644
--- a/src/mongo/db/index/index_access_method.h
+++ b/src/mongo/db/index/index_access_method.h
@@ -387,8 +387,8 @@ public:
* If any key generation errors are encountered and suppressed due to the provided GetKeysMode,
* 'onSuppressedErrorFn' is called.
*/
- using OnSuppressedErrorFn =
- std::function<void(Status status, const BSONObj& obj, boost::optional<RecordId> loc)>;
+ using OnSuppressedErrorFn = std::function<void(
+ Status status, const BSONObj& obj, const boost::optional<RecordId>& loc)>;
void getKeys(OperationContext* opCtx,
const CollectionPtr& collection,
SharedBufferFragmentBuilder& pooledBufferBuilder,
@@ -398,7 +398,7 @@ public:
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id,
+ const boost::optional<RecordId>& id,
OnSuppressedErrorFn&& onSuppressedError = nullptr) const;
/**
@@ -585,7 +585,7 @@ protected:
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const = 0;
+ const boost::optional<RecordId>& id) const = 0;
const IndexCatalogEntry* const _indexCatalogEntry; // owned by IndexCatalog
const IndexDescriptor* const _descriptor;
diff --git a/src/mongo/db/index/index_build_interceptor.cpp b/src/mongo/db/index/index_build_interceptor.cpp
index df708587511..6061ea3b90f 100644
--- a/src/mongo/db/index/index_build_interceptor.cpp
+++ b/src/mongo/db/index/index_build_interceptor.cpp
@@ -177,7 +177,7 @@ Status IndexBuildInterceptor::drainWritesIntoIndex(OperationContext* opCtx,
while (record) {
opCtx->checkForInterrupt();
- RecordId currentRecordId = record->id;
+ auto& currentRecordId = record->id;
BSONObj unownedDoc = record->data.toBson();
// Don't apply this record if the total batch size in bytes would be too large.
@@ -207,7 +207,7 @@ Status IndexBuildInterceptor::drainWritesIntoIndex(OperationContext* opCtx,
// Save the record ids of the documents inserted into the index for deletion later.
// We can't delete records while holding a positioned cursor.
- recordsAddedToIndex.push_back(currentRecordId);
+ recordsAddedToIndex.emplace_back(std::move(currentRecordId));
// Don't continue if the batch is full. Allow the transaction to commit.
if (batchSize == kBatchMaxSize) {
diff --git a/src/mongo/db/index/s2_access_method.cpp b/src/mongo/db/index/s2_access_method.cpp
index a2ea40dd9b1..eaba79ce7eb 100644
--- a/src/mongo/db/index/s2_access_method.cpp
+++ b/src/mongo/db/index/s2_access_method.cpp
@@ -143,7 +143,7 @@ void S2AccessMethod::doGetKeys(OperationContext* opCtx,
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
ExpressionKeysPrivate::getS2Keys(pooledBufferBuilder,
obj,
_descriptor->keyPattern(),
diff --git a/src/mongo/db/index/s2_access_method.h b/src/mongo/db/index/s2_access_method.h
index c25a8b47ce1..38999d95379 100644
--- a/src/mongo/db/index/s2_access_method.h
+++ b/src/mongo/db/index/s2_access_method.h
@@ -76,7 +76,7 @@ private:
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const final;
+ const boost::optional<RecordId>& id) const final;
S2IndexingParams _params;
diff --git a/src/mongo/db/index/s2_bucket_access_method.cpp b/src/mongo/db/index/s2_bucket_access_method.cpp
index 0da4cdc6f63..b9e926a753b 100644
--- a/src/mongo/db/index/s2_bucket_access_method.cpp
+++ b/src/mongo/db/index/s2_bucket_access_method.cpp
@@ -125,7 +125,7 @@ void S2BucketAccessMethod::doGetKeys(OperationContext* opCtx,
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
ExpressionKeysPrivate::getS2Keys(pooledBufferBuilder,
obj,
_descriptor->keyPattern(),
diff --git a/src/mongo/db/index/s2_bucket_access_method.h b/src/mongo/db/index/s2_bucket_access_method.h
index 8996bfe78a5..c2d7186881d 100644
--- a/src/mongo/db/index/s2_bucket_access_method.h
+++ b/src/mongo/db/index/s2_bucket_access_method.h
@@ -76,7 +76,7 @@ private:
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const final;
+ const boost::optional<RecordId>& id) const final;
S2IndexingParams _params;
diff --git a/src/mongo/db/index/wildcard_access_method.cpp b/src/mongo/db/index/wildcard_access_method.cpp
index 4ea3cfc261c..0631158e40d 100644
--- a/src/mongo/db/index/wildcard_access_method.cpp
+++ b/src/mongo/db/index/wildcard_access_method.cpp
@@ -69,7 +69,7 @@ void WildcardAccessMethod::doGetKeys(OperationContext* opCtx,
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
_keyGen.generateKeys(pooledBufferBuilder, obj, keys, multikeyMetadataKeys, id);
}
} // namespace mongo
diff --git a/src/mongo/db/index/wildcard_access_method.h b/src/mongo/db/index/wildcard_access_method.h
index a82e7e616c2..1622941fb8e 100644
--- a/src/mongo/db/index/wildcard_access_method.h
+++ b/src/mongo/db/index/wildcard_access_method.h
@@ -75,7 +75,7 @@ private:
KeyStringSet* keys,
KeyStringSet* multikeyMetadataKeys,
MultikeyPaths* multikeyPaths,
- boost::optional<RecordId> id) const final;
+ const boost::optional<RecordId>& id) const final;
const WildcardKeyGenerator _keyGen;
};
diff --git a/src/mongo/db/index/wildcard_key_generator.cpp b/src/mongo/db/index/wildcard_key_generator.cpp
index 6aa2aa64d7b..c04ba500eb7 100644
--- a/src/mongo/db/index/wildcard_key_generator.cpp
+++ b/src/mongo/db/index/wildcard_key_generator.cpp
@@ -114,7 +114,7 @@ void WildcardKeyGenerator::generateKeys(SharedBufferFragmentBuilder& pooledBuffe
BSONObj inputDoc,
KeyStringSet* keys,
KeyStringSet* multikeyPaths,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
FieldRef rootPath;
auto keysSequence = keys->extract_sequence();
// multikeyPaths is allowed to be nullptr
@@ -139,7 +139,7 @@ void WildcardKeyGenerator::_traverseWildcard(SharedBufferFragmentBuilder& pooled
FieldRef* path,
KeyStringSet::sequence_type* keys,
KeyStringSet::sequence_type* multikeyPaths,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
for (const auto& elem : obj) {
// If the element's fieldName contains a ".", fast-path skip it because it's not queryable.
if (elem.fieldNameStringData().find('.', 0) != std::string::npos)
@@ -185,7 +185,7 @@ bool WildcardKeyGenerator::_addKeyForNestedArray(SharedBufferFragmentBuilder& po
const FieldRef& fullPath,
bool enclosingObjIsArray,
KeyStringSet::sequence_type* keys,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
// If this element is an array whose parent is also an array, index it as a value.
if (enclosingObjIsArray && elem.type() == BSONType::Array) {
_addKey(pooledBufferBuilder, elem, fullPath, keys, id);
@@ -198,7 +198,7 @@ bool WildcardKeyGenerator::_addKeyForEmptyLeaf(SharedBufferFragmentBuilder& pool
BSONElement elem,
const FieldRef& fullPath,
KeyStringSet::sequence_type* keys,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
invariant(elem.isABSONObj());
if (elem.embeddedObject().isEmpty()) {
// In keeping with the behaviour of regular indexes, an empty object is indexed as-is while
@@ -217,7 +217,7 @@ void WildcardKeyGenerator::_addKey(SharedBufferFragmentBuilder& pooledBufferBuil
BSONElement elem,
const FieldRef& fullPath,
KeyStringSet::sequence_type* keys,
- boost::optional<RecordId> id) const {
+ const boost::optional<RecordId>& id) const {
// Wildcard keys are of the form { "": "path.to.field", "": <collation-aware value> }.
KeyString::PooledBuilder keyString(pooledBufferBuilder, _keyStringVersion, _ordering);
keyString.appendString(fullPath.dottedField());
diff --git a/src/mongo/db/index/wildcard_key_generator.h b/src/mongo/db/index/wildcard_key_generator.h
index 085fd191f37..4164fa9aa92 100644
--- a/src/mongo/db/index/wildcard_key_generator.h
+++ b/src/mongo/db/index/wildcard_key_generator.h
@@ -79,7 +79,7 @@ public:
BSONObj inputDoc,
KeyStringSet* keys,
KeyStringSet* multikeyPaths,
- boost::optional<RecordId> id = boost::none) const;
+ const boost::optional<RecordId>& id = boost::none) const;
private:
// Traverses every path of the post-projection document, adding keys to the set as it goes.
@@ -89,7 +89,7 @@ private:
FieldRef* path,
KeyStringSet::sequence_type* keys,
KeyStringSet::sequence_type* multikeyPaths,
- boost::optional<RecordId> id) const;
+ const boost::optional<RecordId>& id) const;
// Helper functions to format the entry appropriately before adding it to the key/path tracker.
void _addMultiKey(SharedBufferFragmentBuilder& pooledBufferBuilder,
@@ -99,7 +99,7 @@ private:
BSONElement elem,
const FieldRef& fullPath,
KeyStringSet::sequence_type* keys,
- boost::optional<RecordId> id) const;
+ const boost::optional<RecordId>& id) const;
// Helper to check whether the element is a nested array, and conditionally add it to 'keys'.
bool _addKeyForNestedArray(SharedBufferFragmentBuilder& pooledBufferBuilder,
@@ -107,12 +107,12 @@ private:
const FieldRef& fullPath,
bool enclosingObjIsArray,
KeyStringSet::sequence_type* keys,
- boost::optional<RecordId> id) const;
+ const boost::optional<RecordId>& id) const;
bool _addKeyForEmptyLeaf(SharedBufferFragmentBuilder& pooledBufferBuilder,
BSONElement elem,
const FieldRef& fullPath,
KeyStringSet::sequence_type* keys,
- boost::optional<RecordId> id) const;
+ const boost::optional<RecordId>& id) const;
WildcardProjection _proj;
const CollatorInterface* _collator;