[SERVER-85673] [CQF] Sargable rewrite bug with $ne inside a $elemMatch against empty array Created: 24/Jan/24  Updated: 25/Jan/24

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Militsa Sotirova Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
Assigned Teams:
Query Optimization
Operating System: ALL
Steps To Reproduce:

Enable sargable rewrites.

> db.test.find() 
{ "_id" : 0, "num" : 2, "a" : { "array" : [ ] } }   
 
> db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "forceClassicEngine"}) 
{ "was" : "trySbeEngine", "ok" : 1 } 
> db.test.aggregate({$match: {$or: [{nonexistent: 1}, {$and: [{"a.array": {$elemMatch: {$ne: "str"}}}, {"num": {$gte: 1}}]}]}}) 
// no results   
 
> db.adminCommand({setParameter: 1, internalQueryFrameworkControl: "tryBonsai"}) 
{ "was" : "forceClassicEngine", "ok" : 1 } 
> db.test.aggregate({$match: {$or: [{nonexistent: 1}, {$and: [{"a.array": {$elemMatch: {$ne: "str"}}}, {"num": {$gte: 1}}]}]}}) 
{ "_id" : 0, "num" : 2, "a" : { "array" : [ ] } } 
> 

Participants:
Linked BF Score: 130

 Description   

There is a bug in the sargable rewrites that comes about when there is a field whose value is an empty array and there is a $ne inside an $elemMatch against that field, among some other stages (see the repro). Note that for the repro, SBE matches classic


Generated at Thu Feb 08 06:58:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.