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

Query: planner returns bad hint error for hint on compound index

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.5.5
    • Component/s: Querying
    • Labels:
      None
    • ALL
    • Hide
      t=db.test;
      for (i=0; i< 1000; i++) {
      	t.insert({a: i%5, b: i%9, c: i%7})
      }
      t.ensureIndex({a:1});
      t.ensureIndex({a: 1, b: 1});
      t.ensureIndex({c: 1});
      t.find({a: {$gt: 1}, b: 1}).explain().cursor
      t.find({a: {$gt: 1}, b: 1}).hint({a: 1})
      t.find({a: {$gt: 1}, b: 1}).hint({b: 1})
      
      Show
      t=db.test; for (i=0; i< 1000; i++) { t.insert({a: i%5, b: i%9, c: i%7}) } t.ensureIndex({a:1}); t.ensureIndex({a: 1, b: 1}); t.ensureIndex({c: 1}); t.find({a: {$gt: 1}, b: 1}).explain().cursor t.find({a: {$gt: 1}, b: 1}).hint({a: 1}) t.find({a: {$gt: 1}, b: 1}).hint({b: 1})

      The query planner returns an error when hinting on a field in a compound index. Note - this happens for the second index field (b), not the first field (a).

      t.find({a: {$gt: 1}, b: 1}).hint({a: 1})
      { "_id" : ObjectId("52efc1e50dba2e4988556ff7"), "a" : 2, "b" : 1, "c" : 2 }
      ...
      
       t.find({a: {$gt: 1}, b: 1}).hint({b: 1})
      error: {
      	"$err" : "Unable to execute query: error processing query: ns=test.new limit=0 skip=0\nTree: $and\n    b == 1.0\n    a $gt 1.0\nSort: {}\nProj: {}\n planner returned error: bad hint",
      	"code" : 17007
      }
      
      t.find({a: 1, b: 1}).hint({b: 1})
      error: {
      	"$err" : "Unable to execute query: error processing query: ns=test.new limit=0 skip=0\nTree: $and\n    a == 1.0\n    b == 1.0\nSort: {}\nProj: {}\n planner returned error: bad hint",
      	"code" : 17007
      }
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            jonathan.abrahams Jonathan Abrahams
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: