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

Hinting an incompatible partial index can return incomplete results

    • Query Execution
    • ALL
    • Hide
      > c = db.col
      test.col
      > c.drop()
      false
      > c.insert({x:100})
      WriteResult({ "nInserted" : 1 })
      > c.createIndex({x:1},{partialFilterExpression:{y:{$exists:true}}})
      {
      	"createdCollectionAutomatically" : false,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > 
      > 
      > c.find({x:100})
      { "_id" : ObjectId("57ee96b1d2002c23be038661"), "x" : 100 }
      >
      > c.find({x:100}).hint({x:1})
      > 
      
      Show
      > c = db.col test.col > c.drop() false > c.insert({x:100}) WriteResult({ "nInserted" : 1 }) > c.createIndex({x:1},{partialFilterExpression:{y:{$exists:true}}}) { "createdCollectionAutomatically" : false, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > > > c.find({x:100}) { "_id" : ObjectId("57ee96b1d2002c23be038661"), "x" : 100 } > > c.find({x:100}).hint({x:1}) >

      The database currently allows for partial indexes to be hinted regardless of the filters applied to the query. When these filters do not align with the partialFilterExpression for an index, there may be documents that match the query but are not included in the index. Forcing index usage via a hint in such a scenario will lead to the database returning incomplete results (a silent logical failure).

      Returning an error is probably the most correct thing to do. Alternatively, the hint could be rejected and the standard plan generation process could be observed.

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            christopher.harris@mongodb.com Chris Harris
            Votes:
            3 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated: