[SERVER-16330] plan cache filters aren't applied if mongoS rewrites the projection of a query Created: 26/Nov/14 Updated: 04/Feb/15 Resolved: 16/Dec/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying, Sharding |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Charlie Page | Assignee: | Charlie Page |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||||||
| Issue Links: |
|
||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||
| Operating System: | ALL | ||||||||||||
| Steps To Reproduce: | See attached js, should not succeed if filters are used on mongoS. |
||||||||||||
| Participants: | |||||||||||||
| Description |
|
If mongoS changes the projection on a query, then the filters aren't applied to the query at all (mongoD runs the normal ranking process). The expected behavior would be either:
|
| Comments |
| Comment by David Storch [ 01/Dec/14 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As far as I can tell from the attached repro script, this is Works as Designed. It is the case that the index filters are not aware of projection rewrites performed by mongos, and therefore that these rewrites must be taken into account when setting filters on the shards. However, in the filterfailure.js script, the index filter doesn't get applied through mongos because mongos is not performing any rewrite. To be more specific, the mongos query in question is
The following elements of this query determine the plan cache key:
The index filter, anticipating that mongos will rewrite the projection to include the sort key, is set with the following plan cache key:
In this case, the collection is not sharded, so the query is simply forwarded to the shard which owns the collection. Since there is just one shard involved, the projection and sort can be forwarded to the shard as is. The sort stage is then performed on the shard alone (mongos does not participate in the sorting). This behavior is clear from a 2.8-style explain of this query:
Since the projection received by mongod is {a: 1} and not {a: 1, b: 1}, it is expected that the index filter will not be applied. I'm closing as Works as Designed for now. Feel free to reopen if there are remaining concerns. Best, |