Planner can create incorrect ixscan leaves for index intersection w/ $elemMatch object

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 2.6.0-rc3
    • Affects Version/s: 2.6.0-rc2
    • Component/s: Querying
    • None
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Repro with this script:

      var t = db.t;
      t.drop();
      
      t.ensureIndex({"shortId": 1});
      t.ensureIndex({"a.b.startDate": 1});
      t.ensureIndex({"a.b.endDate": 1});
      
      // Make _startDate and _endDate indices multikey.
      t.save({a: [{b: {startDate: new Date(), endDate: new Date()}},
                  {b: {startDate: new Date(), endDate: new Date()}}]});
      
      t.find({"shortId": "aj72u4",
              _sites: { $in: [ "foo", "bar" ] },
              _allNamespaces: { $in: [ "1", "2", "3", "4" ] },
              "a.b": { $elemMatch: { startDate: { $lte: new Date(1388462400000) },
                                     endDate: { $gt: new Date(1388462400000) },
                                     _r: { $in: [ BinData(0,true) ] },
                                     _p: { $in: [ BinData(0,true), BinData(0,true)  ] },
                                     _o: { $in: [ BinData(0,true) ] } } }
              }).itcount();
      

      The sixth and final indexed solution generated by the planner should have one index scan over "startDate" and one index scan over "endDate". Instead, both child index scans are over "startDate":

      ------------AND_HASH
      ---------------fetched = 0
      ---------------sortedByDiskLoc = 0
      ---------------getSort = [{ a.b.startDate: 1 }, ]
      ---------------Child 0:
      ---------------IXSCAN
      ------------------keyPattern = { a.b.startDate: 1.0 }
      ------------------direction = 1
      ------------------bounds = field #0['a.b.startDate']: (true, new Date(1388462400000)]
      ------------------fetched = 0
      ------------------sortedByDiskLoc = 0
      ------------------getSort = [{ a.b.startDate: 1 }, ]
      ---------------Child 1:
      ---------------IXSCAN
      ------------------keyPattern = { a.b.startDate: 1.0 }
      ------------------direction = 1
      ------------------bounds = field #0['a.b.startDate']: (new Date(1388462400000), new Date(9223372036854775807)]
      ------------------fetched = 0
      ------------------sortedByDiskLoc = 0
      ------------------getSort = [{ a.b.startDate: 1 }, ]
      

              Assignee:
              David Storch
              Reporter:
              David Storch
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: