[SERVER-14661] Overhead of range scans Created: 23/Jul/14  Updated: 10/Dec/14  Resolved: 23/Jul/14

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

Type: Improvement Priority: Major - P3
Reporter: Ramon Fernandez Marina Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-12871 Seemingly unreasonable overhead to ra... Closed
Participants:

 Description   

db.foo.drop();
 
var filler = '';
for(c=0;c < 100; c++) {
    filler += 'a';
}
  
for( i =0; i < 100000; i++) {
    db.foo.insert({ "n" : Math.floor(100 * Math.random()), "fill" : filler} );
}
 
> db.foo.find().explain()
{
        "cursor" : "BasicCursor",
        "isMultiKey" : false,
        "n" : 100000,
        "nscannedObjects" : 100000,
        "nscanned" : 100000,
        "nscannedObjectsAllPlans" : 100000,
        "nscannedAllPlans" : 100000,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 781,
        "nChunkSkips" : 0,
        "millis" : 15,
        "server" : "skye.local:27017",
        "filterSet" : false
}
> db.foo.find({n:{$gte:0}}).explain()
{
        "cursor" : "BasicCursor",
        "isMultiKey" : false,
        "n" : 100000,
        "nscannedObjects" : 100000,
        "nscanned" : 100000,
        "nscannedObjectsAllPlans" : 100000,
        "nscannedAllPlans" : 100000,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 781,
        "nChunkSkips" : 0,
        "millis" : 39,
        "server" : "skye.local:27017",
        "filterSet" : false
}

In the test above, both queries return the same amount of documents, but looks like the overheard of the range comparison is unexpectedly high. Opening a ticket to see if there's some optimization we can do here.



 Comments   
Comment by Ramon Fernandez Marina [ 23/Jul/14 ]

Turns out the above comparison is not meaningful, so I added a constant to all documents:

db.foo.update({},{$set:{c:1}},{multi:true})

And then tested equality matching against range matching:

> db.foo.find({n:{$gte:0}}).explain()
{
        "cursor" : "BasicCursor",
        "isMultiKey" : false,
        "n" : 100000,
        "nscannedObjects" : 100000,
        "nscanned" : 100000,
        "nscannedObjectsAllPlans" : 100000,
        "nscannedAllPlans" : 100000,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 781,
        "nChunkSkips" : 0,
        "millis" : 35,
        "server" : "tab:27017",
        "filterSet" : false
}
> db.foo.find({c:1}).explain()
{
        "cursor" : "BasicCursor",
        "isMultiKey" : false,
        "n" : 100000,
        "nscannedObjects" : 100000,
        "nscanned" : 100000,
        "nscannedObjectsAllPlans" : 100000,
        "nscannedAllPlans" : 100000,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 781,
        "nChunkSkips" : 0,
        "millis" : 34,
        "server" : "tab:27017",
        "filterSet" : false
}

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