[SERVER-30338] $sort + $limit optimizer failing in some cases Created: 26/Jul/17 Updated: 21/Sep/17 Resolved: 26/Jul/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | 3.4.6 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Ivan Fioravanti | Assignee: | Kelsey Schubert |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Tested on Windows and Linux with MongoDB 3.4.6 |
||
| Attachments: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
| Issue Links: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
| Operating System: | ALL | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: | Import SortLimitBug dump in a new database. Run following aggregation and check Id of last record return (67)
Run second page: Check Id of first record: is 67 instead of 72
Run same queries without $limit and records will be correct |
|||||||||||||||||||||||||||||||||||||||||||||||||||
| Participants: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
We have discovered an issue that we think related to the $sort + $limit optimizer. Second query with a limit of 25 has as first element the last element of the first page (25th) instead of the 26th correct one. Same queries performed without limit works properly. |
| Comments |
| Comment by Kelsey Schubert [ 21/Sep/17 ] |
|
This is likely just the result of your particular system. For example, when I ran the same operations as you described in the ticket, I saw a different sort order than the one you are describing. To ensure a consistent ordering, please include a unique field in your sort order. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-users group. Kind regards, |
| Comment by Ivan Fioravanti [ 27/Jul/17 ] |
|
But why without $limits it works properly an moreover with $limits results is always the same? It this is by design I expect to see different sorted elements in result, while here order is always wrong in the same way and always on first element of the second page. |
| Comment by Kelsey Schubert [ 26/Jul/17 ] |
|
Thank for the very clear reproduction steps in your report. The behavior you're describing is expected, please review my comment on Kind regards, |