summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/plan_cache_indexability.h
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/plan_cache_indexability.h
parentdc076ee0d1c4b9463084b51694957dc63f8ba593 (diff)
downloadmongo-7b42fb9ded007e90bd4961c46afa046af92675a8.tar.gz
SERVER-35333 caching plans for allPaths indexes
Diffstat (limited to 'src/mongo/db/query/plan_cache_indexability.h')
-rw-r--r--src/mongo/db/query/plan_cache_indexability.h46
1 files changed, 42 insertions, 4 deletions
diff --git a/src/mongo/db/query/plan_cache_indexability.h b/src/mongo/db/query/plan_cache_indexability.h
index 3dd4e83ec3e..7f43a60cace 100644
--- a/src/mongo/db/query/plan_cache_indexability.h
+++ b/src/mongo/db/query/plan_cache_indexability.h
@@ -31,6 +31,7 @@
#include <vector>
#include "mongo/base/disallow_copying.h"
+#include "mongo/db/exec/projection_exec_agg.h"
#include "mongo/stdx/functional.h"
#include "mongo/util/string_map.h"
@@ -89,17 +90,48 @@ public:
* Returns a map from index name to discriminator for each index associated with 'path'.
* Returns an empty set if no discriminators are registered for 'path'.
*
- * The object returned by reference is valid until the next call to updateDiscriminators()
- * or until destruction of 'this', whichever is first.
+ * The object returned by reference is valid until the next call to updateDiscriminators() or
+ * until destruction of 'this', whichever is first.
*/
const IndexToDiscriminatorMap& getDiscriminators(StringData path) const;
/**
+ * Construct an IndexToDiscriminator map for the given path, only for the allPaths indexes
+ * which have been included in the indexability state.
+ */
+ IndexToDiscriminatorMap buildAllPathsDiscriminators(StringData path) const;
+
+ /**
* Clears discriminators for all paths, and regenerate them from 'indexEntries'.
*/
void updateDiscriminators(const std::vector<IndexEntry>& indexEntries);
private:
+ using PathDiscriminatorsMap = StringMap<IndexToDiscriminatorMap>;
+
+ /**
+ * A $** index may index an infinite number of fields. We cannot just store a discriminator for
+ * every possible field that it indexes, so we have to maintain some special context about the
+ * index.
+ */
+ struct AllPathsIndexDiscriminatorContext {
+ AllPathsIndexDiscriminatorContext(std::unique_ptr<ProjectionExecAgg> proj,
+ std::string name,
+ const MatchExpression* filter,
+ const CollatorInterface* coll)
+ : projectionExec(std::move(proj)),
+ catalogName(std::move(name)),
+ filterExpr(filter),
+ collator(coll) {}
+
+ std::unique_ptr<ProjectionExecAgg> projectionExec;
+ std::string catalogName;
+
+ // These are owned by the catalog.
+ const MatchExpression* filterExpr; // For partial indexes.
+ const CollatorInterface* collator;
+ };
+
/**
* Adds sparse index discriminators for the sparse index with the given key pattern to
* '_pathDiscriminatorsMap'.
@@ -136,10 +168,16 @@ private:
const CollatorInterface* collator);
/**
- * PathDiscriminatorsMap is a map from field path to index name to IndexabilityDiscriminator.
+ * Adds special state for a $** index. When the discriminators are retrieved for a certain
+ * path, appropriate discriminators for the allPaths index will be included if it includes the
+ * given path.
*/
- using PathDiscriminatorsMap = StringMap<IndexToDiscriminatorMap>;
+ void processAllPathsIndex(const IndexEntry& ie);
+
+ // PathDiscriminatorsMap is a map from field path to index name to IndexabilityDiscriminator.
PathDiscriminatorsMap _pathDiscriminatorsMap;
+
+ std::vector<AllPathsIndexDiscriminatorContext> _allPathsIndexDiscriminators;
};
} // namespace mongo