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

Lost results of search using sort, skip and limit

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.4.2
    • Component/s: None
    • None
    • Environment:
      Docker
    • ALL
    • Hide

      1. Use docker version of mongodb

      docker run -d --name=test_mongo_44 mongo:4.4

      2. Run attached file to populate collection and execute three find requests

      cat test_sort.js | docker exec -i test_mongo_44 mongo
      Show
      1. Use docker version of mongodb docker run -d --name=test_mongo_44 mongo:4.4 2. Run attached file to populate collection and execute three find requests cat test_sort.js | docker exec -i test_mongo_44 mongo

      I found problem on production server and try to prepare minimal example that can reproduce that situation. I try to obtain in generally the same .explain() description of winningPlan, that's a reason why it possible looks ugly or strength. It just example.

      The example use popular pattern of pagination of search request. First request try get first 5 documents, second request try next 5 documents, third request try get first 10 documents (total documents in this example)

      Looks for output:

       

      Query skip 0, limit 5:
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb98") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb99") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb96") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb95") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb97") }
      Query skip 5, limit 5:
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb98") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb96") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb95") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb97") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb9b") }
      Query skip 0, limit 10:
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb9d") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb9e") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb99") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb9c") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb9a") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb98") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb96") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb95") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb97") }
      { "_id" : ObjectId("5fc7a98ff658d92832ebeb9b") }

      As we  can see first and seconds results have intersections with ids:

      5fc7a98ff658d92832ebeb98
      5fc7a98ff658d92832ebeb96
      5fc7a98ff658d92832ebeb95
      5fc7a98ff658d92832ebeb97

      and have no ids:

      5fc7a98ff658d92832ebeb9d
      5fc7a98ff658d92832ebeb9e
      5fc7a98ff658d92832ebeb9c 
      5fc7a98ff658d92832ebeb9a

      which have third result.

       

      In practice this mean that i lost objects when try to paginate request of web app.

       

      I can't reproduce this behavior in versions 4.2, 4.0, 3.6, only in 4.4.2.

      Is it a bug of mongodb?

      P.S. My suggestion is that a new stage "SORT_KEY_GENERATOR" change behavior. It is a general difference between .explain() of 4.2 and 4.4 versions

            Assignee:
            edwin.zhou@mongodb.com Edwin Zhou
            Reporter:
            makhmudov.evgeniy@gmail.com Евгений Махмудов
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: