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

Implement Index Choice based on Partial Filter Expression

    • Type: Icon: New Feature New Feature
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.5
    • Component/s: Index Maintenance
    • Labels:
      None
    • Query Optimization

      Request for index selection based solely on the partialFilterExpression.

      Currently, the query optimizer decides on an index based on the match and sort arguments of a query. With partial indexes, it will also consider the partialFilterExpression, but as implemented, it can still miss an index that would be performant on the query.

      Here's an example where the current implementation is sub-optimal:

      db.foo.dropIndex();
      db.foo.createIndex( { a : 1 }, { partialFilterExpression : { b : { $gte : 5 } } } );
      for (i=1; i<=10; i++) { db.foo.insertOne( { a : i, b : i } ) };
      db.foo.find( { b : { $gte : 5 } }, { _id : 0, a : 1 } ).explain()
      

      Desired result: The query uses the index, and it is a covered query
      Current result: the query performs a collection scan
      Variation: db.foo.find( { a : { $exists: true }, b : { $gte : 5 } }, { _id : 0, a : 1 } ).explain() results in an index scan, but does not cover the query even though the index could cover this query.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            william.cross William Cross
            Votes:
            0 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated: