summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/plan_enumerator.h
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-04-24 13:13:25 -0400
committerDavid Storch <david.storch@10gen.com>2014-05-01 13:38:33 -0400
commit4eb9988846e1e7d49ec26facd9a2ff6b89f8cdde (patch)
tree567f6e8230bf85922dc04026ae692275ff0ea9e2 /src/mongo/db/query/plan_enumerator.h
parent0ee4735ab8fb718b40e2049d014e17736035ba46 (diff)
downloadmongo-4eb9988846e1e7d49ec26facd9a2ff6b89f8cdde.tar.gz
SERVER-13687 fix plan enumeration for compound multikey 2d or 2dsphere indices
Diffstat (limited to 'src/mongo/db/query/plan_enumerator.h')
-rw-r--r--src/mongo/db/query/plan_enumerator.h39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/mongo/db/query/plan_enumerator.h b/src/mongo/db/query/plan_enumerator.h
index 65fb9d7b290..8cccbab61c8 100644
--- a/src/mongo/db/query/plan_enumerator.h
+++ b/src/mongo/db/query/plan_enumerator.h
@@ -273,9 +273,9 @@ namespace mongo {
vector<MemoID>* mandatorySubnodes);
/**
- * Finds a set of predicates that can be safely compounded with 'assigned',
- * under the assumption that we are assignining predicates to a compound,
- * multikey index.
+ * Finds a set of predicates that can be safely compounded with the set
+ * of predicates in 'assigned', under the assumption that we are assigning
+ * predicates to a compound, multikey index.
*
* The list of candidate predicates that we could compound is passed
* in 'couldCompound'. A subset of these predicates that is safe to
@@ -313,8 +313,28 @@ namespace mongo {
* 2) {'a.b': 1, a: {$elemMatch: {b: {$gt: 0}}}}. We cannot combine the
* bounds here because the prefix 'a' is shared by two predicates which
* are not joined together by an $elemMatch.
+ *
+ * NOTE:
+ * Usually 'assigned' has just one predicate. However, in order to support
+ * mandatory predicate assignment (TEXT and GEO_NEAR), we allow multiple
+ * already-assigned predicates to be passed. If a mandatory predicate is over
+ * a trailing field in a multikey compound index, then we assign both a predicate
+ * over the leading field as well as the mandatory predicate prior to calling
+ * this function.
+ *
+ * Ex:
+ * Say we have index {a: 1, b: 1, c: "2dsphere", d: 1} as well as a $near
+ * predicate and a $within predicate over "c". The $near predicate is mandatory
+ * and must be assigned. The $within predicate is not mandatory. Furthermore,
+ * it cannot be assigned in addition to the $near predicate because the index
+ * is multikey.
+ *
+ * In this case the enumerator must assign the $near predicate, and pass it in
+ * in 'assigned'. Otherwise it would be possible to assign the $within predicate,
+ * and then not assign the $near because the $within is already assigned (and
+ * has the same path).
*/
- void getMultikeyCompoundablePreds(const MatchExpression* assigned,
+ void getMultikeyCompoundablePreds(const vector<MatchExpression*>& assigned,
const vector<MatchExpression*>& couldCompound,
vector<MatchExpression*>* out);
@@ -365,6 +385,17 @@ namespace mongo {
AndAssignment* andAssignment);
/**
+ * Generate single-index assignments for queries which contain mandatory
+ * predicates (TEXT and GEO_NEAR, which are required to use a compatible index).
+ * Outputs these assignments into 'andAssignment'.
+ */
+ void enumerateMandatoryIndex(const IndexToPredMap& idxToFirst,
+ const IndexToPredMap& idxToNotFirst,
+ MatchExpression* mandatoryPred,
+ const set<IndexID>& mandatoryIndices,
+ AndAssignment* andAssignment);
+
+ /**
* Try to assign predicates in 'tryCompound' to 'thisIndex' as compound assignments.
* Output the assignments in 'assign'.
*/