$maxScan not working without limit

120 views
Skip to first unread message

Skipy

unread,
Sep 27, 2011, 12:13:46 PM9/27/11
to mongodb-user
Hello,

I ran into the following bug on mongo 1.8.3 (64 bits): $maxScan
behaves incorrectly when limit is missing and when using an index.

It seems that when limit is missing, the maxScan parameter is ignored
if it's > 100. When setting $maxScan to 200 and iterating through a
cursor, the entire result set will be scanned through & returned,
instead of only 200 (because an index is used).

To replicate the bug use this script: http://pastie.org/2600588
and run some queries:

> Q = {'nr': 43, 'ts': {'$lte': 100000, '$gte': 0}}
{ "nr" : 43, "ts" : { "$lte" : 100000, "$gte" : 0 } }
( there is an index on nr & ts )
> count = 0; col.find(Q)._addSpecial( "$maxScan" , 101 ).forEach( function(i) { count += 1; } ); print(count);
1063
> count = 0; col.find(Q)._addSpecial( "$maxScan" , 100 ).forEach( function(i) { count += 1; } ); print(count);
100
> count = 0; col.find(Q)._addSpecial( "$maxScan" , 13 ).forEach( function(i) { count += 1; } ); print(count);
13

Is this a bug, or did I misunderstand the purpose of $maxScan?

Thanks,
Mihnea @ uberVU

Marc

unread,
Sep 27, 2011, 5:07:33 PM9/27/11
to mongodb-user
You are correct; this is not expected behavior. Thank you for finding
this!

I have created a bug in Jira, "SERVER-3965: $maxScan only works for
initial query"
https://jira.mongodb.org/browse/SERVER-3965

Presently, $maxScan is only being applied to the initial return for
the first query results (batch), which is 101 or up to 1MB.

You can see the code on Git Hub here:
https://github.com/mongodb/mongo/commit/aa82a787890de97c2613e719b114f570b5c34d06

Sincerely,
Marc

Jon

unread,
Jan 31, 2013, 10:20:55 PM1/31/13
to mongod...@googlegroups.com
So how does $maxScan work if you provide a limit? For illustrative purposes, assume I have a collection of 1 million documents, I want to $maxScan 100000 of them to look for a certain document, so I add a limit(1). Will Mongo only scan 100k, or will it scan all million? When using explain, it appears that the $maxScan is adhered to, but I haven't tested against the other case yet.

Sam Millman

unread,
Feb 1, 2013, 3:18:03 AM2/1/13
to mongod...@googlegroups.com
MaxScan, as far as my testing goes, should adhere to your rules. If not, and your limit is smaller than the maxbatchsize, then that is another bug.


--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages