[SERVER-18411] bad hint when using named indexes Created: 11/May/15  Updated: 14/May/15  Resolved: 14/May/15

Status: Closed
Project: Core Server
Component/s: Storage
Affects Version/s: 3.0.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Bret Curtis Assignee: Ramon Fernandez Marina
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

db version v3.0.2
git version: 83419b7d5a78599e4b8449e10b0d38878ce624c0
OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014

Participants:

 Description   

2015-05-11T17:02:29.804+0200 I INDEX    [conn24] build index on: mydb.mycol properties: { v: 1, key: { i: 1 }, name: "test_index", ns: "mydb.mycol" }
2015-05-11T17:02:29.804+0200 I INDEX    [conn24] 	 building index using bulk method
2015-05-11T17:02:29.805+0200 I INDEX    [conn24] build index done.  scanned 101 total records. 0 secs
2015-05-11T17:02:29.806+0200 I QUERY    [conn24] assertion 17007 Unable to execute query: error processing query: ns=mydb.mycol limit=0 skip=0
Tree: $and
Sort: {}
Proj: {}
 planner returned error: bad hint ns:mydb.mycol query:{ $hint: { test_index: 1 }, $query: {} }

I see this when using the mongoshell as well as with PyMongo and TxMongo.

The query works when using:

{ $hint: { i: 1 }, $query: {} }



 Comments   
Comment by Ramon Fernandez Marina [ 14/May/15 ]

Understood, thanks for getting back to us psi29a. Closing this ticket now.

Comment by Bret Curtis [ 14/May/15 ]

If that is the case, then no worries. No reason to spend any more time on this. We've corrected it on TxMongo's side to follow your lead on hinting.
https://github.com/twisted/txmongo/commit/0d5d180b580e90c3c35a4126cd8708ad8409ddfb

Cheers and thanks for the help!

Comment by Ramon Fernandez Marina [ 13/May/15 ]

I can't get that syntax to work in the shell in 2.6.9; I also tried with pymongo 2.7.2, but no luck either. Given the rules on hinting I would guess it was a bug that got corrected at some point during the MongoDB 2.7 development cycle. If you're interested in the details we'd need a full reproducer, including the the exact versions of pymongo and MongoDB you're using, as we have not been successful reproducing on our end.

Thanks,
Ramón.

Comment by Bret Curtis [ 12/May/15 ]

Why did this work on MongoDB 2.6 and not on 3.0 ?

$hint: { test_index: 1 }, $query: {}

test_index is the named index.

Comment by Bret Curtis [ 11/May/15 ]

I see the problem now, my code was sending this:

{'$hint': {'email': 1}, '$query': {'external_ids.email': 'test@email'}}

while it should be:

{'$hint': 'email'}, '$query': {'external_ids.email': 'test@email'}}

It looks like this behaviour has changed from 2.6 to 3.0. Right?

Comment by Ramon Fernandez Marina [ 11/May/15 ]

Can you please send the code you're using? I can reproduce this assertion (both in 3.0.2 and 2.6.9) when using the wrong syntax for hinting using the index name:

> db.foo.drop()
> for (i=0;i<200; i++) { db.foo.insert({x:i})}
> db.foo.ensureIndex({x:1}, {name:"test_index"})
// This works:
> db.foo.find({x:{$gte:50}}).hint({x:1})
// This doesn't because of incorrect syntax:
> db.foo.find({x:{$gte:50}}).hint({"test_index":1})
error: {
        "$err" : "Unable to execute query: error processing query: ns=test.foo limit=0 skip=0\nTree: x $gte 50.0\nSort: {}\nProj: {}\n planner returned error: bad hint",
        "code" : 17007
}
// With the right syntax things work:
> db.foo.find({x:{$gte:50}}).hint("test_index")

Comment by Bret Curtis [ 11/May/15 ]

This worked on MongoDB 2.6

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