Find predicate {$gte: MinKey} is inconsistent in SBE

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Consider the collection

      db.test.drop();
      db.test.insertMany([{a: 1}, {a: null}, {}]);
      

      In classic engine find on {a: {$gte: MinKey}} will return all documents,
      but if we force SBE (or use $match - $group pipeline in default configuration), it will not return an empty document:

      rs0 [direct: primary] test> db.test.find({a: {$gte: MinKey}}) // classic
      [
        { _id: ObjectId('67164434cb760047b0d31db1'), a: 1 },
        { _id: ObjectId('67164434cb760047b0d31db2'), a: null },
        { _id: ObjectId('67164434cb760047b0d31db3') }
      ]
      rs0 [direct: primary] test> db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "trySbeEngine"})
      rs0 [direct: primary] test> db.test.find({ a: { $gte: MinKey } }) // sbe
      [
        { _id: ObjectId('67164434cb760047b0d31db1'), a: 1 },
        { _id: ObjectId('67164434cb760047b0d31db2'), a: null }
      ]
      rs0 [direct: primary] test> db.test.createIndex({a: 1})
      a_1
      rs0 [direct: primary] test> db.test.find({ a: { $gte: MinKey } }). // sbe with index
      [
        { _id: ObjectId('67164434cb760047b0d31db2'), a: null },
        { _id: ObjectId('67164434cb760047b0d31db3') },
        { _id: ObjectId('67164434cb760047b0d31db1'), a: 1 }
      ]
      

      The empty document is skipped in collection scan because {$gte: MinKey} is translated into exists() in stage builders:

      filter {traverseF(s1, lambda(l2.0) { exists(move(l2.0)) }, true)}
      

      and in empty document field "a" doesn't exist.

      But in case of index scan the predicate is absorbed into index bounds and works as expected.

      This predicate itself is pretty strange and only comes around as work-around for some issues to make sure the index is covering the query. Example: SERVER-12769

              Assignee:
              Unassigned
              Reporter:
              Ivan Fefer
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: