[SERVER-64141] SBE returns different answer from classic engine for $in with regex Created: 02/Mar/22  Updated: 29/Oct/23  Resolved: 12/Apr/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.0.0-rc0

Type: Bug Priority: Blocker - P1
Reporter: David Storch Assignee: Mihai Andrei
Resolution: Fixed Votes: 0
Labels: query-director-triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
is related to SERVER-54493 [SBE] Can't match on a regexp field Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.3
Sprint: QE 2022-04-04, QE 2022-03-21, QE 2022-04-18
Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 12/Apr/22 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-64141 [SBE] Support checking equality against regexes in $in
Branch: master
https://github.com/mongodb/mongo/commit/f416d27ea4141be5457af898fd4f7c13f2d5cba3

Comment by Rushan Chen [ 14/Mar/22 ]

steve.la Nikita will take a look.

Comment by Ethan Zhang (Inactive) [ 08/Mar/22 ]

steve.la bernard.gorman We need to find a team for this ticket since this is a correctness bug

Generated at Thu Feb 08 05:59:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.