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

$elemMatch with dotted field compared to null returns incorrect results when using SBE

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Execution
    • ALL
    • Hide

      Repro, run with --mongodSetParameters='

      {featureFlagSbeFull: true}

      '

      const coll = db.coll;
      assert(coll.drop());
      assert.commandWorked(coll.insert([
      	{
      		_id : 6,
      		b : [[]]
      	}
      ]))
      
      
      const q = [{$match: {b: {$elemMatch: {'x.y': null}}}}];
      
      jsTestLog(coll.aggregate([{$_internalInhibitOptimization: {}}, ...q]).toArray())
      jsTestLog(coll.explain().aggregate([{$_internalInhibitOptimization: {}}, ...q])) 
      // uses SBE for collscan, then doc sources, returns [ { "_id" : 6, "b" : [ [ ] ] } ]
      jsTestLog(coll.aggregate(q).toArray())
      // uses SBE, returns [] 
      jsTestLog(coll.explain().aggregate(q)) 
      

      SBE plan

      [1] filter {((isArray(s3) && traverseF(s3, lambda(l6.0) { (typeMatch(l6.0, 24) && 
          let [
              l7.0 = getField(l6.0, \"x\") 
          ] 
          in 
              if (typeMatch(l7.0, 24) ?: false) 
              then traverseF(move(l7.0), lambda(l8.0) { 
                  if (isObject(l8.0) ?: false) 
                  then traverseF(getField(move(l8.0), \"y\"), lambda(l9.0) { ((
                      if (typeMatch(l9.0, 1024) ?: true) 
                      then null 
                      else move(l9.0) 
                  == null) ?: false) }, false) 
                  else false 
              }, false) 
              else !((isArray(l6.0) ?: false)) 
      ) }, false)) ?: false)} 
      [1] scan s1 s2 none none none none none none [s3 = b] @\"\" true false
      
      Show
      Repro, run with --mongodSetParameters=' {featureFlagSbeFull: true} ' const coll = db.coll; assert (coll.drop()); assert .commandWorked(coll.insert([ { _id : 6, b : [[]] } ])) const q = [{$match: {b: {$elemMatch: { 'x.y' : null }}}}]; jsTestLog(coll.aggregate([{$_internalInhibitOptimization: {}}, ...q]).toArray()) jsTestLog(coll.explain().aggregate([{$_internalInhibitOptimization: {}}, ...q])) // uses SBE for collscan, then doc sources, returns [ { "_id" : 6, "b" : [ [ ] ] } ] jsTestLog(coll.aggregate(q).toArray()) // uses SBE, returns [] jsTestLog(coll.explain().aggregate(q)) SBE plan [1] filter {((isArray(s3) && traverseF(s3, lambda(l6.0) { (typeMatch(l6.0, 24) && let [ l7.0 = getField(l6.0, \ "x\" ) ] in if (typeMatch(l7.0, 24) ?: false ) then traverseF(move(l7.0), lambda(l8.0) { if (isObject(l8.0) ?: false ) then traverseF(getField(move(l8.0), \ "y\" ), lambda(l9.0) { (( if (typeMatch(l9.0, 1024) ?: true ) then null else move(l9.0) == null ) ?: false ) }, false ) else false }, false ) else !((isArray(l6.0) ?: false )) ) }, false )) ?: false )} [1] scan s1 s2 none none none none none none [s3 = b] @\ "\" true false
    • QE 2025-03-17, QE 2025-03-31, QE 2025-04-14
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      An $elemMatch on a dotted path compared to null does not match classic behavior when the values in the documents are doubly nested arrays. See repro below.

      This looks similar to SERVER-87238, but SERVER-87238 seems to be a block processing specific issue. This doesn't use BP to repro (no time-series collection)

            Assignee:
            rushan.chen@mongodb.com Rushan Chen
            Reporter:
            matt.boros@mongodb.com Matt Boros
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None