summaryrefslogtreecommitdiff
path: root/src/mongo/db/fts/fts_index_format.cpp
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2020-05-04 13:06:15 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-05-05 19:24:43 +0000
commitb7d70ba03a92d70b5bda98960c8764007081d575 (patch)
tree19daecbadaae99536252729a1708414f00b3eb99 /src/mongo/db/fts/fts_index_format.cpp
parent9e80c5c46ec01e61e020681b393ce8e529049836 (diff)
downloadmongo-b7d70ba03a92d70b5bda98960c8764007081d575.tar.gz
SERVER-47928 Fix quadradic KeyString insert behavior in fts indexes.
Diffstat (limited to 'src/mongo/db/fts/fts_index_format.cpp')
-rw-r--r--src/mongo/db/fts/fts_index_format.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/mongo/db/fts/fts_index_format.cpp b/src/mongo/db/fts/fts_index_format.cpp
index f6f5e379c02..1993f518115 100644
--- a/src/mongo/db/fts/fts_index_format.cpp
+++ b/src/mongo/db/fts/fts_index_format.cpp
@@ -110,7 +110,8 @@ MONGO_INITIALIZER(FTSIndexFormat)(InitializerContext* context) {
return Status::OK();
}
-void FTSIndexFormat::getKeys(const FTSSpec& spec,
+void FTSIndexFormat::getKeys(SharedBufferFragmentBuilder& pooledBufferBuilder,
+ const FTSSpec& spec,
const BSONObj& obj,
KeyStringSet* keys,
KeyString::Version keyStringVersion,
@@ -137,11 +138,12 @@ void FTSIndexFormat::getKeys(const FTSSpec& spec,
TermFrequencyMap term_freqs;
spec.scoreDocument(obj, &term_freqs);
+ auto sequence = keys->extract_sequence();
for (TermFrequencyMap::const_iterator i = term_freqs.begin(); i != term_freqs.end(); ++i) {
const string& term = i->first;
double weight = i->second;
- KeyString::Builder keyString(keyStringVersion, ordering);
+ KeyString::PooledBuilder keyString(pooledBufferBuilder, keyStringVersion, ordering);
for (const auto& elem : extrasBefore) {
keyString.appendBSONElement(elem);
}
@@ -154,11 +156,9 @@ void FTSIndexFormat::getKeys(const FTSSpec& spec,
keyString.appendRecordId(*id);
}
- /*
- * Insert a copy to only allocate as much buffer space as necessary.
- */
- keys->insert(keyString.getValueCopy());
+ sequence.push_back(keyString.release());
}
+ keys->adopt_sequence(std::move(sequence));
}
BSONObj FTSIndexFormat::getIndexKey(double weight,
@@ -179,7 +179,8 @@ BSONObj FTSIndexFormat::getIndexKey(double weight,
return b.appendElements(key).obj();
}
-void FTSIndexFormat::_appendIndexKey(KeyString::Builder& keyString,
+template <typename KeyStringBuilder>
+void FTSIndexFormat::_appendIndexKey(KeyStringBuilder& keyString,
double weight,
const string& term,
TextIndexVersion textIndexVersion) {