[SERVER-16350] Wrong index choice when request contains _id in query + sort command Created: 29/Nov/14 Updated: 25/Jun/15 Resolved: 03/Dec/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance, Querying |
| Affects Version/s: | 2.6.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | Romain Pechayre | Assignee: | David Storch |
| Resolution: | Duplicate | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
Hello, I encountered a strange behavior in Mongo 2.6.x. i am using Mongoid in ruby talk to MongoDB and Mongoid allows having default sort command. When I run the following command : Person.find("someindex") in Mongoid, it is translated into ).sort(created_at: -1) Mongoid is not really smart by generating such query because we know we will get either 0 or 1 result, so the sort operator does not make sense. However, I've found cases where MongoDB is even less smart and caches the wrong index, including the created_at field. I would expect MongoDB to automatically use the _id index whenever it is present in the query, no matter other fields that are present in the query, in partcular sort commands. I already had a discussion about this on google group: |
| Comments |
| Comment by David Storch [ 03/Dec/14 ] |
|
Hi rpechayr, Thanks for the bug report. This appears to be a duplicate of Our server development team has several open improvement tickets that could fix this and similar problems with caching bad plans:
I hope this response adequately addresses the concerns brought forth in this ticket. Please feel free to reach out with any further questions or comments. Best, |