Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-2977

Doc behavior changes related to indexing negations such as $not and $ne

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: v1.3.3
    • Component/s: manual
    • Last comment by Customer:
      true
    • Actual Time:
      4

      Description

      There have been a few behavior changes in v2.6 related to negations. These should probably go into the 2.6 release notes? See SERVER-13324 and SERVER-12532 or come talk to me for details.

      1) In 2.4 it is possible to get different results for negations depending on whether or not an indexed plan is used:

      > t.drop()
      true
      > t.save({a: 1})
      > t.save({b: 1})
      > t.find({a: {$not: {$gt: 3}}})
      { "_id" : ObjectId("5330803029b74d493d375e46"), "a" : 1 }
      { "_id" : ObjectId("5330803529b74d493d375e47"), "b" : 1 }
      > t.ensureIndex({a: 1})
      > t.find({a: {$not: {$gt: 3}}})
      { "_id" : ObjectId("5330803029b74d493d375e46"), "a" : 1 }

      In 2.6, the results will always be the same regardless of whether or not there is an index:

      > t.drop()
      true
      > t.save({a: 1})
      WriteResult({ "nInserted" : 1 })
      > t.save({b: 1})
      WriteResult({ "nInserted" : 1 })
      > t.find({a: {$not: {$gt: 3}}})
      { "_id" : ObjectId("5330808b3a40985f27706d1e"), "a" : 1 }
      { "_id" : ObjectId("5330808d3a40985f27706d1f"), "b" : 1 }
      > t.ensureIndex({a: 1})
      {
      	"createdCollectionAutomatically" : false,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > t.find({a: {$not: {$gt: 3}}})
      { "_id" : ObjectId("5330808d3a40985f27706d1f"), "b" : 1 }
      { "_id" : ObjectId("5330808b3a40985f27706d1e"), "a" : 1 }

      2) Negation predicates will no longer use sparse indices. This is necessary in order to preserve the invariant from (1), namely that a negation query should return the same results for indexed and unindexed plans. See SERVER-13324.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kay.kim Kay Kim (Inactive)
              Reporter:
              david.storch David Storch
              Participants:
              Last commenter:
              Jonathan Dahl Jonathan Dahl
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since reply:
                7 years, 30 weeks, 2 days ago
                Date of 1st Reply: