summaryrefslogtreecommitdiff
path: root/src/mongo/db/index_names.cpp
diff options
context:
space:
mode:
authorIan Boros <ian.boros@10gen.com>2018-06-23 18:45:19 -0400
committerIan Boros <ian.boros@10gen.com>2018-07-24 13:35:48 -0400
commitca931f5259bd4c40ea5e710f04608143202fd2aa (patch)
tree615671817151f563cb7dfc364a9002ce02d09086 /src/mongo/db/index_names.cpp
parent35528523c00b72a210dc5b78a427d90ed1c14331 (diff)
downloadmongo-ca931f5259bd4c40ea5e710f04608143202fd2aa.tar.gz
SERVER-35330 expand allPaths indexes in planner
Diffstat (limited to 'src/mongo/db/index_names.cpp')
-rw-r--r--src/mongo/db/index_names.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/mongo/db/index_names.cpp b/src/mongo/db/index_names.cpp
index 557a7c636bb..7773bec86a5 100644
--- a/src/mongo/db/index_names.cpp
+++ b/src/mongo/db/index_names.cpp
@@ -43,16 +43,24 @@ const string IndexNames::HASHED = "hashed";
const string IndexNames::BTREE = "";
const string IndexNames::ALLPATHS = "allPaths";
+const StringMap<IndexType> kIndexNameToType = {
+ {IndexNames::GEO_2D, INDEX_2D},
+ {IndexNames::GEO_HAYSTACK, INDEX_HAYSTACK},
+ {IndexNames::GEO_2DSPHERE, INDEX_2DSPHERE},
+ {IndexNames::TEXT, INDEX_TEXT},
+ {IndexNames::HASHED, INDEX_HASHED},
+ {IndexNames::ALLPATHS, INDEX_ALLPATHS},
+};
+
// static
string IndexNames::findPluginName(const BSONObj& keyPattern) {
BSONObjIterator i(keyPattern);
while (i.more()) {
BSONElement e = i.next();
- string fieldName(e.fieldName());
+ StringData fieldName(e.fieldNameStringData());
if (String == e.type()) {
return e.String();
- } else if ((fieldName == "$**") ||
- (fieldName.size() > 4 && fieldName.substr(e.fieldNameSize() - 5) == ".$**")) {
+ } else if ((fieldName == "$**") || fieldName.endsWith(".$**")) {
return IndexNames::ALLPATHS;
} else
continue;
@@ -76,20 +84,12 @@ bool IndexNames::isKnownName(const string& name) {
}
// static
-IndexType IndexNames::nameToType(const string& accessMethod) {
- if (IndexNames::GEO_2D == accessMethod) {
- return INDEX_2D;
- } else if (IndexNames::GEO_HAYSTACK == accessMethod) {
- return INDEX_HAYSTACK;
- } else if (IndexNames::GEO_2DSPHERE == accessMethod) {
- return INDEX_2DSPHERE;
- } else if (IndexNames::TEXT == accessMethod) {
- return INDEX_TEXT;
- } else if (IndexNames::HASHED == accessMethod) {
- return INDEX_HASHED;
- } else {
+IndexType IndexNames::nameToType(StringData accessMethod) {
+ auto typeIt = kIndexNameToType.find(accessMethod);
+ if (typeIt == kIndexNameToType.end()) {
return INDEX_BTREE;
}
+ return typeIt->second;
}
} // namespace mongo