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

Optimise $all/$and to select smallest subset as initial index bounds

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.12, 3.0.7, 3.1.9
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
    • Fully Compatible
    • Quint Iteration 3, QuInt A (10/12/15)

      Currently clauses in a $all will be evaluated in the order that they are provided to the query. This can lead to cases where a superset is being searched to find values that are contained within a smaller subset of the wanted values.

      Consider trying to find all documents that have tags showing that they are an Italian and have a Michelin star within a collection of restaurants. There will be a large number of documents with the tag "Italian" but very few with the tag "Michelin".

      If the tags are entered into the $all clause in alphabetical order, the search will take longer as the larger set of "Italian" documents must be searched again for the "Michelin" tag. If the tag order is reversed, then we search the smaller set of "Michelin" matching documents to find those who match "Italian".

      The optimisation here would be to remove the dependency on the order of documents in an $all clause.

      Changes in this case should handle situations where the entities within the $all clause are not simply fields, but also documents which may have several levels of depth.

            david.storch@mongodb.com David Storch
            david.hows David Hows
            4 Vote for this issue
            15 Start watching this issue