- 
    Type:Improvement 
- 
    Resolution: Unresolved
- 
    Priority:Major - P3 
- 
    None
- 
    Affects Version/s: 2.6.0-rc0
- 
    Component/s: Index Maintenance, Querying
- 
    None
- 
        Query Optimization
- 
        (copied to CRM)
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
A document with a missing value are stored as if they were                                                                                                                                    
explicitly given the value 'null'.  Given:                                                                                                                                                
X = { b : 1 }                                                                                                                                                                                  
Y = { a : null, b : 1 }
X and Y look identical from within a standard index on
{ a : 1 }
However a sparse index on
{ a : 1 } will treat X and Y differently,                                                                                                                             
storing Y and not storing X.                                                                                                                                                                    
We can safely use an index on $exists queries in the following cases:                                                                                                                                              
     {a:{ $exists:true }} - normal index helps, but we must still fetch                                                                                                                              
     {a:{ $exists:true }} - sparse index is exact                                                                                                                                                    
     {a:{ $exists:false }} - normal index requires a fetch                                                                                                                                           
     {a:{ $exists:false }} - never                                                                                                                                                             
- is depended on by
- 
                    SERVER-13298 distinct doesn't use index to distinct multikey dotted fields -         
- Closed
 
-         
- 
                    SERVER-18861 Queries matching null value should be fully covered by index -         
- Backlog
 
-         
- is duplicated by
- 
                    SERVER-52845 $exists works slowly -         
- Closed
 
-         
- 
                    SERVER-67378 Index null values and missing values differently -         
- Closed
 
-         
- 
                    SERVER-17376 Allow $exists to efficiently use indexes -         
- Closed
 
-         
- is related to
- 
                    SERVER-6293 Index only query fills in missing values with null -         
- Closed
 
-         
- 
                    SERVER-12557 $exists could use index -         
- Closed
 
-         
- 
                    SERVER-55065 Null queries should be covered by index where possible with current index format -         
- Closed
 
-         
- 
                    SERVER-14832 Distinct command result set may include or exclude null/undefined depending on presence of index -         
- Needs Scheduling
 
-         
- 
                    SERVER-18861 Queries matching null value should be fully covered by index -         
- Backlog
 
-         
- 
                    SERVER-100683 Stop using undefined BSON type in indexes to represent empty arrays -         
- Backlog
 
-         
- 
                    SERVER-12262 Use full index scan as proxy for collection scan in order to make certain queries covered -         
- Closed
 
-         
- related to
- 
                    SERVER-23229 Projection incorrectly returns null value instead of missing field to user if projection is covered -         
- Backlog
 
-         
- 
                    SERVER-67378 Index null values and missing values differently -         
- Closed
 
-         
- 
                    SERVER-104707 Create a new fuzzer variant that uses limited number of fields -         
- Backlog
 
-         
- 
                    SERVER-54811 Bad query plans for $exists:true queries -         
- Backlog
 
-         
- 
                    SERVER-105069 Use index for $eq to $$REMOVE expression -         
- Backlog
 
-         
- mentioned in
- 
                    Page Loading...