summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/planner_ixselect.cpp
diff options
context:
space:
mode:
authoryarai <yuta.arai@10gen.com>2018-09-06 14:23:22 -0400
committeryarai <yuta.arai@10gen.com>2018-09-20 09:24:19 -0400
commitd5c17e385f543f0afdc4acd5331cc5514549981f (patch)
tree3ade8c3d608169b5a99c4bd2ff31bf8ccc927b30 /src/mongo/db/query/planner_ixselect.cpp
parent6818230171cb12727892802c608ba9247815ef06 (diff)
downloadmongo-d5c17e385f543f0afdc4acd5331cc5514549981f.tar.gz
SERVER-35331 Allow hinting an all paths index
Diffstat (limited to 'src/mongo/db/query/planner_ixselect.cpp')
-rw-r--r--src/mongo/db/query/planner_ixselect.cpp43
1 files changed, 37 insertions, 6 deletions
diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp
index 70deacf2d5b..b6b2633a944 100644
--- a/src/mongo/db/query/planner_ixselect.cpp
+++ b/src/mongo/db/query/planner_ixselect.cpp
@@ -313,22 +313,53 @@ void QueryPlannerIXSelect::getFields(const MatchExpression* node,
}
// static
-void QueryPlannerIXSelect::findRelevantIndices(const stdx::unordered_set<std::string>& fields,
- const std::vector<IndexEntry>& allIndices,
- std::vector<IndexEntry>* out) {
+std::vector<IndexEntry> QueryPlannerIXSelect::findIndexesByHint(
+ const BSONObj& hintedIndex, const std::vector<IndexEntry>& allIndices) {
+ std::vector<IndexEntry> out;
+ BSONElement firstHintElt = hintedIndex.firstElement();
+ if (firstHintElt.fieldNameStringData() == "$hint"_sd &&
+ firstHintElt.type() == BSONType::String) {
+ auto hintName = firstHintElt.valueStringData();
+ for (auto&& entry : allIndices) {
+ if (entry.identifier.catalogName == hintName) {
+ LOG(5) << "Hint by name specified, restricting indices to "
+ << entry.keyPattern.toString();
+ out.push_back(entry);
+ }
+ }
+ } else {
+ for (auto&& entry : allIndices) {
+ if (SimpleBSONObjComparator::kInstance.evaluate(entry.keyPattern == hintedIndex)) {
+ LOG(5) << "Hint specified, restricting indices to " << hintedIndex.toString();
+ out.push_back(entry);
+ }
+ }
+ }
+
+ return out;
+}
+
+// static
+std::vector<IndexEntry> QueryPlannerIXSelect::findRelevantIndices(
+ const stdx::unordered_set<std::string>& fields, const std::vector<IndexEntry>& allIndices) {
+
+ std::vector<IndexEntry> out;
for (auto&& entry : allIndices) {
BSONObjIterator it(entry.keyPattern);
BSONElement elt = it.next();
if (fields.end() != fields.find(elt.fieldName())) {
- out->push_back(entry);
+ out.push_back(entry);
}
}
+
+ return out;
}
std::vector<IndexEntry> QueryPlannerIXSelect::expandIndexes(
- const stdx::unordered_set<std::string>& fields, const std::vector<IndexEntry>& allIndexes) {
+ const stdx::unordered_set<std::string>& fields,
+ const std::vector<IndexEntry>& relevantIndices) {
std::vector<IndexEntry> out;
- for (auto&& entry : allIndexes) {
+ for (auto&& entry : relevantIndices) {
if (entry.type == IndexType::INDEX_ALLPATHS) {
expandIndex(entry, fields, &out);
} else {