[SERVER-10844] Single shard queries can be optimized (sort/skip) Created: 23/Sep/13  Updated: 28/May/19  Resolved: 12/Jun/14

Status: Closed
Project: Core Server
Component/s: Querying, Sharding
Affects Version/s: None
Fix Version/s: 2.7.2

Type: Improvement Priority: Major - P3
Reporter: ning Assignee: Greg Studer
Resolution: Done Votes: 1
Labels: pull-request
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to SERVER-41329 Improve skip performance in mongos wh... Closed
Participants:

 Description   

on sharding cluster , if:

  • the query will hit only shard (query with shardkey)
  • query with large skip

mongos will ask mongod to reply all the matched records, and do skip on mongos. which is not efficient because no INDEX is used. and too much data is transfer between mongod and mongos

see this explain:

    mongos> db.test_collection.find({'_uid': 500}).skip(1000).limit(5).explain()
    {
     "clusteredType" : "ParallelSort",
     "shards" : {
        "set_test_2/10.65.16.245:7611,10.65.19.26:7611,10.65.19.52:7611" : [
            {
               "cursor" : "BtreeCursor _uid_1",
               "n" : 1005, //useless
               "nscannedObjects" : 1005,
               "nscanned" : 1005,
               "nscannedObjectsAllPlans" : 1005,
               "nscannedAllPlans" : 1005,
               },
               "server" : "xxxxxxxx:7611"
            }
        ]
     },
     ......
 
    }

we can just pass the query to the shard like what we did on not-sharded collection.



 Comments   
Comment by Githook User [ 12/Jun/14 ]

Author:

{u'username': u'gregstuder', u'name': u'Greg Studer', u'email': u'greg@10gen.com'}

Message: SERVER-10844 if only one shard is used we can just pass the query to the shard

Also removes dead code, add comments from parallel.cpp.

Based on changes from idning <idning@gmail.com>
Branch: master
https://github.com/mongodb/mongo/commit/5f9a4b0850954fb2c4f5775fbe84237bf0bf5168

Comment by Greg Studer [ 23/May/14 ]

Moved into 2.7.2.

Comment by ning [ 19/Nov/13 ]

how's the Code Review?

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