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

different result when query hint hint different indexes

    XMLWordPrintable

    Details

    • Type: Question
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Works as Designed
    • Affects Version/s: 3.0.12, 3.2.16, 4.0.0-rc0
    • Fix Version/s: None
    • Component/s: Indexing
    • Labels:
      None

      Description

      //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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: