[SERVER-17221] Query on key-val array using $all and $elemMatch does not seem to correctly use indexes Created: 07/Feb/15 Updated: 09/Feb/15 Resolved: 09/Feb/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 2.6.7 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Pep Martinez | Assignee: | David Storch |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Operating System: | ALL | ||||||||
| Participants: | |||||||||
| Description |
|
Having a collection with elements with a 'tags' array, where each element in the array is {k:<key>, v:<value>}, with an index {'tags.k': 1, 'tags.v': 1} A query of the form correctly makes use of the index. However, a query like: does not make use of the index and produces a full scan |
| Comments |
| Comment by Pep Martinez [ 09/Feb/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
perfect, thanks a lot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by David Storch [ 09/Feb/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi pep.martinez, Thanks for the additional info! I've identified this report as a duplicate of Best, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Pep Martinez [ 09/Feb/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
as it seems, the problem appears when the index covers something else, and not just the tags field, see below:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by David Storch [ 09/Feb/15 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi pep.martinez, Thanks for the bug report. However, I have not been able to reproduce this issue. The shell session below suggests that the planner is generating the correct query plan both with and without $all.
Both explains indicate that the index {"tags.k": 1, "tags.v": 1} is being used to answer the query. Furthermore, both explains have the same index bounds:
These are the expected index bounds for this query. Here are some follow up questions which hopefully will help us track down the issue:
Best, |