Is Cursor.skip() On Indexed Keys Always Faster?
I have 2 databases: slow and fast; each of which was fed with 4096 entries. The age key is a unique random integer that was generated with this script: var arr = [] while(arr.lengt
Solution 1:
Neither of your queries are doing a filter on age
, so there is no reason to use the index.
If you add a condition on age
, there will be a difference (even if minimal with so few documents)
> pageNumber=18;nPerPage=20; db.slow.find({age:{$gt:200}}).
skip(pageNumber > 0 ? ((pageNumber-1)*nPerPage) : 0).limit(nPerPage).
explain("executionStats")
# "executionTimeMillis" : 14,# "inputStage" : {# "stage" : "COLLSCAN",
> pageNumber=18;nPerPage=20; db.fast.find({age:{$gt:200}}).
skip(pageNumber > 0 ? ((pageNumber-1)*nPerPage) : 0).limit(nPerPage).
explain("executionStats"
# "executionTimeMillis" : 0,# "inputStage" : {# "stage" : "IXSCAN",
Post a Comment for "Is Cursor.skip() On Indexed Keys Always Faster?"