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

Prune redundant index bound

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1.9
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL
    • Query 2019-01-28, Query 2019-02-25
    • 45

      We hit this invariant when dealing with wildcard indexes and a query on a multikey field: 

      https://github.com/10gen/mongo/blob/637adda0cefae579448117efcd868fa36f1010c0/src/mongo/db/query/index_bounds_builder.cpp#L1017

      This will be hit because the list of index bounds for the wildcard index contains a redundant index bound, (a range of values is covered by two bounds).  

      Reproduction: 

      db.mycoll.drop();
      db.mycoll.createIndex({"$**":1});
      db.mycoll.insert({a:[1,2,3]});
      db.mycoll.count({ 'a.0.0.0':{ $exists: true }});
      

      This produces this failure:

      INVALID BOUNDS: field #0['$_path']["a.0.0", "a.0.0"], ["a.0.0.", "a.0.0/"), ["a.0.0.0", "a.0.0.0"], ["a.0.0.0.", "a.0.0.0/"), field #1['a.0.0.0'][MinKey, MaxKey]kp = { $_path: 1.0, a.0.0.0: 1.0 }}}{{scanDir = 1

       These bounds are wrong because  "a.0.0/" in the second bound pair is greater than "a.0.0.0" in the third pair. (Comparison is done by string comparison). Check out attached BF for the full backtrace!

      There exists code which is supposed to account for the case of redundant index bounds for a multi-key field, and prune the redundant index bound. 

      https://github.com/mongodb/mongo/blob/d1f23f929359ab6a7a996cc35d1e063e0e9a12a3/src/mongo/db/query/planner_wildcard_helpers.cpp#L424-L443

      However, this logic does not capture the case above. To complete this ticket will involve changing this logic to act correctly when seeing the case above. 

       

       

       

       

       

            Assignee:
            arun.banala@mongodb.com Arun Banala
            Reporter:
            brigitte.lamarche@mongodb.com Brigitte Lamarche (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: