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

Index null values and missing values differently

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 2.6.0-rc0
    • Fix Version/s: Backlog
    • Component/s: Indexing, Querying
    • Labels:
      None
    • Case:

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                14 Vote for this issue
                Watchers:
                29 Start watching this issue

                Dates

                • Created:
                  Updated: