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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 2.6.0-rc2
    • Fix Version/s: 2.6.0-rc3
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL

      Description

      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 }, ]

        Attachments

          Activity

            People

            Assignee:
            david.storch David Storch
            Reporter:
            david.storch David Storch
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: