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

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

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

      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@mongodb.com David Storch
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: