[SERVER-39764] Negation of $in with embedded array can incorrectly plan from the cache, triggering invariant Created: 22/Feb/19  Updated: 29/Oct/23  Resolved: 18/Mar/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 4.1.8
Fix Version/s: 4.0.9, 4.1.10

Type: Bug Priority: Major - P3
Reporter: James Wahlin Assignee: Ian Boros
Resolution: Fixed Votes: 0
Labels: afz
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Related
related to SERVER-40691 $nin:[[],...] queries are not indexed Closed
is related to SERVER-38949 Incorrect index bounds for {$ne: ["St... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0
Steps To Reproduce:

db.test.drop()
 
db.test.createIndex({"obj": 1})
db.test.createIndex({"obj": 1, "abc": 1})
 
db.test.find({'obj': {$ne: 'def'}})
db.test.find({'obj': {$ne: 'def'}})
db.test.find({'obj': {$not: {$in: [ [1] ]}}})

Sprint: Query 2019-03-11, Query 2019-03-25
Participants:
Linked BF Score: 67

 Description   

This issue started with the commit for SERVER-38949. Under that ticket we ban index use for negation of equality to array. It is still possible however to generate a plan cache entry for a negation of equality to non-array, and to then use the cached entry for negation of equality to array.

To address we will likely want to modify the plan cache to discriminate between distinguish between array and non-array values for {$not: {$in: ...}} entries.

The invariant triggered is:

Invariant failure *tightnessOut == IndexBoundsBuilder::EXACT src/mongo/db/query/index_bounds_builder.cpp 429 



 Comments   
Comment by Kelsey Schubert [ 05/Apr/19 ]

This issue doesn't result in an invariant in any stable release.

Comment by Githook User [ 03/Apr/19 ]

Author:

{'email': 'puppyofkosh@gmail.com', 'name': 'Ian Boros', 'username': 'puppyofkosh'}

Message: SERVER-39764 Fix plan caching for negation of equality to array
Branch: v4.0
https://github.com/mongodb/mongo/commit/e9b5dc04ae3001c32758720d53fa9e1c899b1358

Comment by Ian Boros [ 18/Mar/19 ]

We should do this backport at the same time as BACKPORT-3837.

Comment by Githook User [ 18/Mar/19 ]

Author:

{'name': 'Ian Boros', 'username': 'puppyofkosh', 'email': 'puppyofkosh@gmail.com'}

Message: SERVER-39764 fix bug where $in is planned from cache incorrectly
Branch: master
https://github.com/mongodb/mongo/commit/9950774372d4b47a0610fb810f49aeb274a3ff54

Generated at Thu Feb 08 04:53:02 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.