summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/planner_ixselect.cpp
diff options
context:
space:
mode:
authorIan Boros <ian.boros@10gen.com>2018-07-31 13:32:15 -0400
committerIan Boros <ian.boros@10gen.com>2018-08-31 10:59:42 -0400
commit7b42fb9ded007e90bd4961c46afa046af92675a8 (patch)
treeab8158bdb18fb1145cb51f25036d935949ee4181 /src/mongo/db/query/planner_ixselect.cpp
parentdc076ee0d1c4b9463084b51694957dc63f8ba593 (diff)
downloadmongo-7b42fb9ded007e90bd4961c46afa046af92675a8.tar.gz
SERVER-35333 caching plans for allPaths indexes
Diffstat (limited to 'src/mongo/db/query/planner_ixselect.cpp')
-rw-r--r--src/mongo/db/query/planner_ixselect.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp
index 86bd638c3fc..888c2c81717 100644
--- a/src/mongo/db/query/planner_ixselect.cpp
+++ b/src/mongo/db/query/planner_ixselect.cpp
@@ -56,7 +56,7 @@ std::size_t numPathComponents(StringData path) {
}
/**
- * Given a single allPaths index, and a set of fields which are being queried, create 'mock'
+ * Given a single allPaths index, and a set of fields which are being queried, create a virtual
* IndexEntry for each of the appropriate fields.
*/
void expandIndex(const IndexEntry& allPathsIndex,
@@ -77,10 +77,7 @@ void expandIndex(const IndexEntry& allPathsIndex,
{}, // multikey paths
true, // sparse
false, // unique
- // TODO: SERVER-35333: for plan caching to work, each IndexEntry must have
- // a unique name. We violate that requirement here by giving each
- // "expanded" index the same name. This must be fixed.
- allPathsIndex.name,
+ {allPathsIndex.identifier.catalogName, fieldName},
allPathsIndex.filterExpr,
allPathsIndex.infoObj,
allPathsIndex.collator);
@@ -265,18 +262,16 @@ void QueryPlannerIXSelect::getFields(const MatchExpression* node,
}
}
+void QueryPlannerIXSelect::getFields(const MatchExpression* node,
+ stdx::unordered_set<string>* out) {
+ getFields(node, "", out);
+}
+
// static
void QueryPlannerIXSelect::findRelevantIndices(const stdx::unordered_set<std::string>& fields,
const std::vector<IndexEntry>& allIndices,
std::vector<IndexEntry>* out) {
for (auto&& entry : allIndices) {
- if (entry.type == INDEX_ALLPATHS) {
- // Should only have one field of the form {"$**" : 1}.
- invariant(entry.keyPattern.nFields() == 1);
- expandIndex(entry, fields, out);
- continue;
- }
-
BSONObjIterator it(entry.keyPattern);
BSONElement elt = it.next();
if (fields.end() != fields.find(elt.fieldName())) {
@@ -285,6 +280,21 @@ void QueryPlannerIXSelect::findRelevantIndices(const stdx::unordered_set<std::st
}
}
+std::vector<IndexEntry> QueryPlannerIXSelect::expandIndexes(
+ const stdx::unordered_set<std::string>& fields, const std::vector<IndexEntry>& allIndexes) {
+ std::vector<IndexEntry> out;
+ for (auto&& entry : allIndexes) {
+ if (entry.type == IndexType::INDEX_ALLPATHS) {
+ // Should only have one field of the form {"path.$**" : 1} or {"$**" : 1}.
+ invariant(entry.keyPattern.nFields() == 1);
+ expandIndex(entry, fields, &out);
+ } else {
+ out.push_back(entry);
+ }
+ }
+ return out;
+}
+
// static
// This is the public method which does not accept an ElemMatchContext.
bool QueryPlannerIXSelect::compatible(const BSONElement& keyPatternElt,