The query planner instructs an IXSCAN (or other index access stage) to deduplicate based on whether the index is multikey. $** indices, however, may contain multiple keys for a document in the absence of arrays. Consider the example of a collection which contains the document {a: {b: 1, c: 1}} with the index {"$**": 1}. The index will contain the following keys, both referring to the same document:
- {$_path: "a.b", "a.b": 1}
- {$_path: "a.c", "a.c": 1}
The planner, however, will generate an IndexEntry which is not marked as multikey, since there are no array paths:
As a result, a $** IXSCAN used to answer a query for which both of the index keys are in bounds will fail to deduplicate. The only known predicate for which this can happen is $exists. See the repro steps below for an example query that returns the same document twice.
- is depended on by
-
SERVER-36198 Enable $** index builds by default in non-test configurations
- Closed