[SERVER-2556] Query with empty $nin takes considerably longer than without it Created: 15/Feb/11  Updated: 30/Mar/12  Resolved: 23/Feb/11

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

Type: Bug Priority: Major - P3
Reporter: Lennart Koopmann Assignee: Aaron Staple
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-2565 ignore always true query expressions ... Backlog
Operating System: ALL
Participants:

 Description   

I noticed this behavior when searching for slow queries: Queries using an empty $nin modifier take a lot more time to finish than queries not including the empty notifier:

lennart ~$ mongo
MongoDB shell version: 1.6.3
connecting to: test
> use graylog2
switched to db graylog2
> db.messages.count();
185998
> db.messages.find({deleted:false, message:{$nin:[]}}).explain();
{
"cursor" : "BtreeCursor deleted_1",
"nscanned" : 185131,
"nscannedObjects" : 185131,
"n" : 185131,
"millis" : 560,
"indexBounds" :

{ "deleted" : [ [ false, false ] ] }

}

> db.messages.find(

{deleted:false}

).explain();
{
"cursor" : "BtreeCursor deleted_1",
"nscanned" : 185131,
"nscannedObjects" : 185131,
"n" : 185131,
"millis" : 158,
"indexBounds" :

{ "deleted" : [ [ false, false ] ] }

}

This is a 400ms difference for 185998 documents in the collection. I noticed this in a collection with ~4,000,000 documents (on a not that fast machine) and got a difference of 20 seconds. "message" always has a String as value.

Let me know if you need any more information.



 Comments   
Comment by Aaron Staple [ 23/Feb/11 ]

I think we can let SERVER-2565 cover this issue.

Comment by Aaron Staple [ 16/Feb/11 ]

Saw a difference on my machine as well. Filed SERVER-2565.

Generated at Thu Feb 08 03:00:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.