[SERVER-12925] Queries with projections limiting returned fields can result in full collection scans Created: 26/Feb/14 Updated: 11/Jul/16 Resolved: 27/Feb/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 2.6.0-rc0 |
| Fix Version/s: | 2.6.0-rc1 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Jeff lee | Assignee: | hari.khalsa@10gen.com |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
| Participants: |
| Description |
|
Hi there, It seems that if you specify fields to return in a projection, the query can end up doing a full collection scan even if there are indexes that should support the query predicates. This doesn't appear to be an explain bug from what I can tell. |
| Comments |
| Comment by Jeff lee [ 27/Feb/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks Hari! I look forward to testing it out. There are some great new features in 2.6. This is probably a topic for another JIRA, but I'm curious how this change will affect situations where a collection scan would be preferred over the index scan. I'm imagining a scenario where the existing index is on a key with low cardinality, especially if there has been a lot of document movement and the query needs to hit disk. In this situation I would imagine that a full scan would be a better choice. I know that in previous versions, the first plan to return n documents (1001?) was ranked higher than others. Is this still the case in 2.6? | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by hari.khalsa@10gen.com [ 27/Feb/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you for reporting this! I actually submitted a fix the other day for this issue and it will be in RC1: https://github.com/mongodb/mongo/commit/a3d910925350d2f0204b41ea145e24f74e5c39ce In brief, we used to consider a collection scan as a possible way to execute the query even when an indexed plan was available. If a collection scan found as many matching documents as an indexed plan, we'd prefer the collection scan because it had both of the values we were projecting (and the index only had one of them). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeff lee [ 26/Feb/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Sure thing...here ya go. Note that I reduced the size of the collection and simplified the projection.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by J Rassi [ 26/Feb/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Could you paste the output of re-running those two queries with explain(true)? That gives verbose explain output. |