|
Before changing the index format, it is only possible to cover null queries in certain conditions:
- the index being scanned is not multikey, because indexes alone cannot distinguish between null, missing, undefined, and empty array values
- the query is either not projecting (as in the case of either legacy or aggregation count) or the query is projecting directly only onto the _id field. This is possible because _id fields are guaranteed to be unique and present, so we can have at most one _id field set to null in the index (meaning we would always get the right value for _id from the index).
Furthermore, we can optimize counts to use two COUNT_SCANs joined by an OR stage when a single null interval is encountered (instead of just using an INDEX_SCAN with a. filter).
This branched off of https://jira.mongodb.org/browse/SERVER-18861.
|