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

Unable to force predicate evaluation order with new query framework

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • Labels:
    • Minor Change

      In version 2.4 and before, predicate order was significant to the query optimizer. Thus if selectivity of a query predicate was known, it could influence the planner.

      Now, query plans are normalized into a generic query execution tree and re-ordered, so predicate evaluation order can be "surprising" based on the sort order of the actual data being queried for. There is no way to override this behavior because in both cases, the optimizer chooses the correct "plan" but can't choose the correct predicate to evaluate first.

      Attaching a test which if run in 2.4 and then 2.5.5 shows the change in behavior. One example uses a hash_merge of 3 $and predicates on a single multi-key index, one with a very low cardinality.

      The second example shows a 2 predicate $and query where the optimizer chooses the wrong query predicate.

            david.storch@mongodb.com David Storch
            dan@mongodb.com Daniel Pasette (Inactive)
            2 Vote for this issue
            8 Start watching this issue