For queries with multiple predicates over a multikey field, you can't intersect the index bounds. Suppose there is a multikey index on field 'a'. The following query
db.t.find({a: {$lte: 0, $gte: 1}});
would have empty index bounds if 'a' were not a multikey field. Since it is multikey, however, we either use bounds
[-Infinity, 0]
or
[1, Infinity]
Which bounds to use is chosen arbitrarily. As an optimization, we could make sure that we always choose the smallest interval over which to perform the index scan. For instance, for the query
db.t.find({a: {$gt: 4, $gte: 5}});
we would choose
[5, Infinity]
rather than
(4, Infinity]
because the former is a subset of the latter.
- is duplicated by
-
SERVER-14519 $and $ne performance degradation in 2.6
- Closed
-
SERVER-15214 $nin operator avoid query execution over a specific index
- Closed
-
SERVER-15658 Query with $in and $nin doesn't use index correctly
- Closed
- is related to
-
SERVER-13273 multiple predicates for $all and multiKey index is order dependent
- Closed
-
SERVER-16042 Optimise $all/$and to select smallest subset as initial index bounds
- Closed
- related to
-
SERVER-12470 document and audit multikey bounds behavior
- Closed
-
SERVER-18364 Ensure non-negation predicates get chosen over negation predicates for multikey index bounds construction
- Closed