[SERVER-28720] Database search using find() with 2 indexes of heirarchical sub-documents wrongly return empty cursor Created: 10/Apr/17 Updated: 15/May/17 Resolved: 15/May/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 3.2.12 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Samaresh Singh | Assignee: | Asya Kamsky |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||||||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: | The data:
The indexes:
WRONG Result of search (looking non empty array entr(ies) in the indexed sub-documents) :
The result returns 0 entries. If remove the indexes using db.coll2.dropIndexes() and conduct the search again I get the RIGHT result as :
|
||||||||||||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||||||||||||
| Description |
|
The data:
The indexes:
WRONG Result of search (looking non empty array entr(ies) in the indexed sub-documents) :
The results returns 0 entries. If remove the indexes using db.coll2.dropIndexes() and conduct the search again I get the RIGHT result as :
|
| Comments |
| Comment by Asya Kamsky [ 17/Apr/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
samaresh.singh you are describing a case where presence of a multikey index (an index on an array) changes the results of a query that's comparing to an array. That's precisely what the other two tickets (which are probably fundamentally the same) are also describing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Samaresh Singh [ 14/Apr/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I believe this one is different from I tested with 3 sub-document arrays i.e. "a.b", "a.c" and "a.d" and then created indexes using all those sub-document array fields, I got the error but NOT if created index using up to 2 of those array fields i.e. n -1 array fields. I extended the test using 4 and 5 array fields and found that if I have indexes on (n-1) of the array fields I get the correct result. Moreover, if I create indexes using the first element of all the array fields ("a.b.0", "a.c.0", etc) then I get the correct result as well. I get error only if I create indexes using all the array fields. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Samaresh Singh [ 10/Apr/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Mark, Yes, I have also replicated the issue on 3.4.2 earlier as well. Sincerely | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Samaresh Singh [ 10/Apr/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Mark, Unfortunately your index is not the same as mine. I also fixed the issue using the index that you are also showing, where the index is based on the first element of the sub-document i.e. "a.b.0" and "a.c.0" But in the original problem the indexes that I describe are on "a.b" and "a.c" only and not on the first element of the arrays. There is a big difference there. I can use the index here on the first element of the arrays and get away with this use-case but it is a clear bug. BTW mentioned below is the explain(true) output:
Sincerely | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Mark Agarunov [ 10/Apr/17 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello samaresh.singh, Thank you for the report. Unfortunately I'm unable to reproduce the behavior you've described. Repeating the steps you outlined with the same data appears to give the proper result with the indexes:
Please run the query where you are seeing this issue with .explain(true) appended and provide the output, for example:
This should give a better idea of how mongod is running the query. Thanks, |