Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-12869

Index null values and missing values differently

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.0-rc0
    • Component/s: Index Maintenance, Querying
    • None
    • Query Optimization

      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

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            samantha.ritter@mongodb.com Samantha Ritter (Inactive)
            Votes:
            33 Vote for this issue
            Watchers:
            65 Start watching this issue

              Created:
              Updated: