[SERVER-22451] Allow predicates to be covered when indexed path is prefix of matched path Created: 03/Feb/16 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Viacheslav Usov | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Query Optimization
|
| Participants: |
| Description |
|
Consider the following script.
==>
So far so good. Yet, doing explain() on that reveals the following:
I may be misinterpreting the output, but it seems to me that the filter {"_id.b" : 1}is applied AFTER the full document has been retrieved, NOT when scanning the index. I am led to this conclusion by seeing the filter spec in the FETCH stage and seeing
in its stats. So, basically, when the index is on a sub-document, and the query filter includes the sub-document's fields, the server does not seem to understand that it could use the index to evaluate the filter; it goes to the collection instead. That can be very costly. Some background as to why this is important. The _id index is mandatory. It is therefore desirable to make it useful. It is also non-configurable, so one pretty much has to make _id a sub-document except in simplest cases. |
| Comments |
| Comment by Viacheslav Usov [ 08/Feb/16 ] |
|
Unfortunately, the referenced documentation does not deal with this issue at hand. As far as I can tell, this issue is not addressed anywhere at all. So I suggest, if the feature does not make it (any time soon), explain in the documentation that a single-field index, if the field is a sub-document, cannot efficiently support range queries with additional filters on the sub-document's fields. |
| Comment by Kelsey Schubert [ 04/Feb/16 ] |
|
Hi viaus, Thank you for opening this ticket. Currently, MongoDB does not support the behavior that you are requesting. For additional information, please see our documentation regarding indexes on embedded documents. I am marking this ticket as a new feature to be scheduled during the next round of planning. Updates will be posted here as they happen. Kind regards, |