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

[CQF] Invalid index scan plan constructed for compound query

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.3.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • ALL
    • QO 2022-12-12, QO 2022-12-26
    • 162

      I have a set of documents that I insert into a collection, I create a compound index {a: 1, x: 1} and then I run a query:

      {$match: {$and: [ { "a.b" : 1 }, { "a.x" : 1 } ]}} 
      

      The optimizer constructs a plan which fails to match the following document:

      {a: [{b: 1}, {x: 1}]}.  
      

      The plan chosen by the optimizer is an index scan followed by two filters, one for the a.b predicate and one for the a.x predicate, and then the fetch comes later. The problem is that the two filter are applied to the index keys, so only a key that matches both predicates under the $and will pass the filters. But, if ‘a’ is an array, it may have multiple index keys, one which satisfies the first filter and one which satisfies the second. This would match in classic. 

            Assignee:
            david.percy@mongodb.com David Percy
            Reporter:
            hana.pearlman@mongodb.com Hana Pearlman
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: