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

Partial index isSubsetOf could be more precise for $or / $in

    • Query Optimization

      When a partial filter expression uses $or, we sometimes don't recognize that it can satisfy a query using $or. For example:

      > db.c.createIndex({a: 1}, {partialFilterExpression: {$or: [ {a: {$lt: 0}}, {a: {$gt: 10}} ]}})
      {
              "numIndexesBefore" : 1,
              "numIndexesAfter" : 2,
              "createdCollectionAutomatically" : true,
              "ok" : 1
      }
      > for (a=-2; a<15; ++a) db.c.insert({a})
      WriteResult({ "nInserted" : 1 })
      > db.c.find({$or: [ {a: -1}, {a: 12} ]}).explain()
      {
          ...
                      "winningPlan" : {
                              "stage" : "COLLSCAN",
          ...
      }
      

      This query should use the index, because any document matching {a: -1} will be indexed, and any document matching {a: 12} will be indexed.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            david.percy@mongodb.com David Percy
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: