Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10844

Single shard queries can be optimized (sort/skip)

      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.

            Assignee:
            greg_10gen Greg Studer
            Reporter:
            idning ning
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: