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

SBE returns different answer from classic engine for $in with regex

    • Fully Compatible
    • ALL
    • v5.3
    • QE 2022-04-04, QE 2022-03-21, QE 2022-04-18

      In the classic engine, when $in contains a regular expression, a document matches if either 1) it stores exactly the same regex, or 2) it stores a string which matches the regex:

      > db.version()
      5.2.1
      > db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: true})
      { "was" : true, "ok" : 1 }
      > db.c.drop()
      true
      > db.c.insert({a: "foo"})
      WriteResult({ "nInserted" : 1 })
      > db.c.insert({a: /foo/})
      WriteResult({ "nInserted" : 1 })
      > db.c.find({a: {$in: [1, /foo/]}})
      { "_id" : ObjectId("621ffc0239b4116350452341"), "a" : "foo" }
      { "_id" : ObjectId("621ffc0639b4116350452343"), "a" : /foo/ }
      

      SBE, in contrast, only returns documents containing strings matching the regex. If we enable SBE and run the same query, the result set now contains just a single document instead of two documents:

      > db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: false})
      { "was" : true, "ok" : 1 }
      > db.c.find({a: {$in: [1, /foo/]}})
      { "_id" : ObjectId("621ffc0239b4116350452341"), "a" : "foo" }
      

      It looks like we dealt with this situation already for regex match expressions outside of a $in under SERVER-54493, but the same changes were never implemented for regexes inside of an $in.

            Assignee:
            mihai.andrei@mongodb.com Mihai Andrei
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: