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

different result when query hint hint different indexes

    • Type: Icon: Question Question
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.0.12, 3.2.16, 4.0.0-rc0
    • Component/s: Index Maintenance
    • None

      //collection indexes
      > db.Collection.getIndexes()> db.Collection.getIndexes()
      [ 
      ... 
      { "v" : 2, "unique" : true, "key" : { "user" : 1, "word" : 1 }, "name" : "user_1_word_1", "ns" : "sample.Collection", "background" : true }, 
      { "v" : 2, "key" : { "user.$id" : 1, "word" : 1, "image" : 1 }, "name" : "user.$id_1_word_1_image_1", "ns" : "sample.Collection", "background" : true }]
      

      query results with different results

      // storeage Engine: wiredTiger
      > db.Collection.find({"user" : DBRef("_User", ObjectId("5a5d783bee920a005896c55f"))},{"_id":1,"user":1}).hint("user_1_word_1").count()
      39
      > db.Collection.find({"user" : DBRef("_User", ObjectId("5a5d783bee920a005896c55f"))},{"_id":1,"user":1}).hint("user.$id_1_word_1_image_1").count()
      8
      

      index form will affect the data? Or were there right?

      I reproduces on v3.0, v3.2, v4.0-rc, may be affect more. reproduce process:

      // download attachments to $data_full_path
      // md5: a14368dbab317182a4826caa0e7bc41d  sample.tgz
      // pull mongo images
      docker pull mongo:3.4.0-rc
      docker run -v $data_full_path:/x mongo:4.0-rc  --setParameter failIndexKeyTooLong=false
      // another terminal in docker
      mongorestore --db sample --dir=./sample
      // then query
      mongo 127.0.0.1:27017/sample --eval 'db.Collection.find({"user" : DBRef("_User", ObjectId("5a5d783bee920a005896c55f"))},{"_id":1,"user":1}).hint("user_1_word_1").count()'
      // result: 39
      mongo 127.0.0.1:27017/sample --eval 'db.Collection.find({"user" : DBRef("_User", ObjectId("5a5d783bee920a005896c55f"))},{"_id":1,"user":1}).hint("user.$id_1_word_1_image_1").count()'
      // result: 8

      Any help will be appreciate.

        1. sample.tgz
          488 kB
          Jiangcheng Wu

            Assignee:
            william.byrne@mongodb.com William Byrne III
            Reporter:
            wujiangcheng Jiangcheng Wu
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: