[SERVER-14557] querying with hashed borders broke in 2.6 Created: 15/Jul/14 Updated: 10/Dec/14 Resolved: 15/Jul/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying, Sharding |
| Affects Version/s: | 2.6.0, 2.6.1, 2.6.2, 2.6.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Daniel Breitlauch | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 3 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Operating System: | ALL | ||||
| Steps To Reproduce: | 1. Create sharded collection with shardkey as hashed _id. db.collection.find( }).hint( { "_id" : "hashed"}) Behavior in 2.4: Query to one shard and use of index there. |
||||
| Participants: | |||||
| Description |
|
It was possible in 2.4 to query a sharded collection by hashedkey with hashed borders like this: db.collection.find( }).hint( { "_id" : "hashed"}) The range values are chunk borders. An explain returns BtreeCursor but scannedObjects is indication a whole table scan on all shards. "_id" : [ , { "$maxElement" : 1 } ] The same problem arises in mongoDB's own hadoop connector when using hashed sharded collections. (https://github.com/mongodb/mongo-hadoop) |
| Comments |
| Comment by J Rassi [ 16/Jul/14 ] |
|
That is a known issue. See SERVER-14400. |
| Comment by Daniel Breitlauch [ 16/Jul/14 ] |
|
Thanks a lot! Although while testing I encountered some strange behavior. ) ) The explain shows correctly all documents fetched from one shard but: shows that all 3 shards got queried. The 2 other shards without documents do have: Why does the switch issues queries to all shards? |
| Comment by Greg Studer [ 15/Jul/14 ] |
|
This was broken behavior in v2.4 that unfortunately happened to work in this case - query operators apply to the document data itself, not the index keys. In order to do chunk range queries over shard keys (which are themselves index keys), you'll want to use the .min()/.max() cursor methods with .hint(). These methods accept the (potentially hashed) index keys, not document values, and will do what you want (including doing the right thing for compound shard keys, which won't work with $gt/$lt). http://docs.mongodb.org/manual/reference/method/cursor.min/#cursor.min |