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

index bounds exclude Infinity for $or query

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.5.5
    • Affects Version/s: 2.5.4
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Hide
      > t = db.t
      test.t
      > t.drop()
      true
      > t.ensureIndex({a: 1})
      > t.insert({a: Infinity})
      Insert WriteResult({ "ok" : 1, "n" : 1 })
      > t.find()
      { "_id" : ObjectId("52a73a410ae4a72f57475846"), "a" : Infinity }
      > t.find({a: {$gt: 1}})
      { "_id" : ObjectId("52a73a410ae4a72f57475846"), "a" : Infinity }
      > t.find({$or: [{a: {$gt: 1}}, {a: {$lt: 3}}]})
      // The previous query should return the document, but it returns nothing.
      
      Show
      > t = db.t test.t > t.drop() true > t.ensureIndex({a: 1}) > t.insert({a: Infinity}) Insert WriteResult({ "ok" : 1, "n" : 1 }) > t.find() { "_id" : ObjectId( "52a73a410ae4a72f57475846" ), "a" : Infinity } > t.find({a: {$gt: 1}}) { "_id" : ObjectId( "52a73a410ae4a72f57475846" ), "a" : Infinity } > t.find({$or: [{a: {$gt: 1}}, {a: {$lt: 3}}]}) // The previous query should return the document, but it returns nothing.

      Consider the query

      {$or: [{a: {$gt: 1}}, {a: {$lt: 3}}]}
      

      with an index on field 'a'. The first branch of the $or has index bounds

      (1, Infinity]

      and the second branch of the $or has index bounds

      [-Infinity, 3)

      . Since these two branches are children of an $or, the final index bounds should be the union of these two intervals, which is

      [-Infinity, Infinity]
      

      However, the actual index bounds are

      [-Infinity, Infinity)
      

      The bug is that the upper bound should be inclusive, but instead it is exclusive.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: