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

Use index on find all

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Index Maintenance
    • None

    Description

      It appears that find all is not using my index. The supposition is that find all may be ignoring indexes other than BasicCursor? It would be advantageous if the query used the covered index without having to resort to a hint.

      Sample "Test" Collection Schema

      {
       _id: ObjectId(<whatever>),
       a: <whatever>,
       b: <whatever>,
       c: <whatever>,
       d: <whatever>,
       e: {
          f: <whatever>,
          g: <whatever>
       }
      }

      Index on "Test"

      db.test.ensureIndex( { "a": NumberInt(1), "c": NumberInt(1), "_id": NumberInt(1), "d": NumberInt(1) }, 
      	             { name: "a_1_c_1__id_1_d_1", background: true } );

      Query without hint and query with hint...

      > db.test.find({},{d:1}).explain();
      {
      "cursor" : "BasicCursor",
      "isMultiKey" : false,
      "n" : 752,
      "nscannedObjects" : 752,
      "nscanned" : 752,
      "nscannedObjectsAllPlans" : 752,
      "nscannedAllPlans" : 752,
      "scanAndOrder" : false,
      "indexOnly" : false,
      "nYields" : 4,
      "nChunkSkips" : 0,
      "millis" : 5,
      "indexBounds" : {
      	
      },
      "server" : <whatever>
      }
       
      > db.test.find({},{d:1}).hint("a_1_c_1__id_1_d_1").explain();
      {
      "cursor" : "BtreeCursor a_1_c_1__id_1_d_1",
      "isMultiKey" : false,
      "n" : 752,
      "nscannedObjects" : 752,
      "nscanned" : 752,
      "nscannedObjectsAllPlans" : 752,
      "nscannedAllPlans" : 752,
      "scanAndOrder" : false,
      "indexOnly" : true,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "millis" : 0,
      "indexBounds" : {
       "a" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ],
       "c" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ],
       "_id" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ],
       "d" : [ [ { "$minElement" : 1 }, { "$maxElement" : 1 } ] ]
      },
      "server" : <whatever>
      }

      http://stackoverflow.com/questions/18790163/mongodb-index-use-on-find-all-without-hint

      Attachments

        Activity

          People

            Unassigned Unassigned
            ezchdahal John Turner
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: