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

multiple predicates for $all and multiKey index is order dependent

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.0-rc1
    • Component/s: Querying
    • Labels:
      None
    • ALL

      In 2.6.0-rc1 I have an array "attr" which is indexed. Its contents are strings. In a query of type:

      db.prod2.find({attr:{$all:["string1","string2","string3"]}})
      

      The nscanned seems to be dependent on the order of values inside the $all list. Putting the more selective string first causes nscanned to be equal to number of documents with that string present.

      Explain(true) shows only one index boundary is considered - the one that's listed first.

      Note: this does not happen if the array elements are subdocuments and $elemMatch is used - then explain(true) shows that each of the elements in the $all list are tried and the one that's most selective is chosen regardless of the order they are given in.

            Assignee:
            david.storch@mongodb.com David Storch
            Reporter:
            asya.kamsky@mongodb.com Asya Kamsky
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: