summaryrefslogtreecommitdiff
path: root/src/mongo/db/index/expression_keys_private.cpp
diff options
context:
space:
mode:
authorGregory Noma <gregory.noma@gmail.com>2019-08-15 13:33:23 -0400
committerGregory Noma <gregory.noma@gmail.com>2019-08-15 13:33:23 -0400
commit80598be3b424fbe69b08a46b71f9098aa768b925 (patch)
tree314f203283ee6f2420db9f956b68be791fc704f1 /src/mongo/db/index/expression_keys_private.cpp
parentb2a1804f242cc70f163c6b8d108437af209b11f6 (diff)
downloadmongo-80598be3b424fbe69b08a46b71f9098aa768b925.tar.gz
SERVER-41728 Make HaystackAccessMethod generate keys using KeyString
Diffstat (limited to 'src/mongo/db/index/expression_keys_private.cpp')
-rw-r--r--src/mongo/db/index/expression_keys_private.cpp50
1 files changed, 16 insertions, 34 deletions
diff --git a/src/mongo/db/index/expression_keys_private.cpp b/src/mongo/db/index/expression_keys_private.cpp
index d3ef7c6a93e..847da8f61cb 100644
--- a/src/mongo/db/index/expression_keys_private.cpp
+++ b/src/mongo/db/index/expression_keys_private.cpp
@@ -59,36 +59,6 @@ using namespace mongo;
namespace dps = ::mongo::dotted_path_support;
//
-// Helper functions for getHaystackKeys
-//
-
-/**
- * Build a new BSONObj with root in it. If e is non-empty, append that to the key.
- * Insert the BSONObj into keys.
- * Used by getHaystackKeys.
- */
-void addKey(const string& root,
- const BSONElement& e,
- KeyStringSet* keys,
- KeyString::Version keyStringVersion,
- Ordering ordering,
- boost::optional<RecordId> id) {
- BSONObjBuilder buf;
- buf.append("", root);
-
- if (e.eoo())
- buf.appendNull("");
- else
- buf.appendAs(e, "");
-
- KeyString::HeapBuilder keyString(keyStringVersion, buf.obj(), ordering);
- if (id) {
- keyString.appendRecordId(*id);
- }
- keys->insert(keyString.release());
-}
-
-//
// Helper functions for getS2Keys
//
@@ -437,7 +407,7 @@ void ExpressionKeysPrivate::getHaystackKeys(const BSONObj& obj,
hashHaystackElement(y, bucketSize));
}
- verify(otherFields.size() == 1);
+ invariant(otherFields.size() == 1);
BSONElementSet all;
@@ -448,14 +418,26 @@ void ExpressionKeysPrivate::getHaystackKeys(const BSONObj& obj,
// We're indexing a document that doesn't have the secondary non-geo field present.
// XXX: do we want to add this even if all.size() > 0? result:empty search terms
// match everything instead of only things w/empty search terms)
- addKey(root, BSONElement(), keys, keyStringVersion, ordering, id);
+ KeyString::HeapBuilder keyString(keyStringVersion, ordering);
+ keyString.appendString(root);
+ keyString.appendNull();
+ if (id) {
+ keyString.appendRecordId(*id);
+ }
+ keys->insert(keyString.release());
} else {
// Ex:If our secondary field is type: "foo" or type: {a:"foo", b:"bar"},
// all.size()==1. We can query on the complete field.
// Ex: If our secondary field is type: ["A", "B"] all.size()==2 and all has values
// "A" and "B". The query looks for any of the fields in the array.
- for (BSONElementSet::iterator i = all.begin(); i != all.end(); ++i) {
- addKey(root, *i, keys, keyStringVersion, ordering, id);
+ for (const auto& elem : all) {
+ KeyString::HeapBuilder keyString(keyStringVersion, ordering);
+ keyString.appendString(root);
+ keyString.appendBSONElement(elem);
+ if (id) {
+ keyString.appendRecordId(*id);
+ }
+ keys->insert(keyString.release());
}
}
}