[SERVER-12584] Query: planner returns bad hint error for hint on compound index Created: 03/Feb/14  Updated: 03/Feb/14  Resolved: 03/Feb/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.5.5
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Jonathan Abrahams Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-10340 Do not require hint() with the full i... Closed
Operating System: ALL
Steps To Reproduce:

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})

Participants:

 Description   

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
}



 Comments   
Comment by Scott Hernandez (Inactive) [ 03/Feb/14 ]

As you have no index on the hinted index ({b:1}) this is the correct error message.

See the docs. The hint must be a index spec/def or string which resolves to a valid index spec/def.
http://docs.mongodb.org/manual/reference/method/cursor.hint/

Generated at Thu Feb 08 03:28:56 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.