[SERVER-55112] Behaviour of distinct differs between collections and views Created: 10/Mar/21 Updated: 29/Oct/23 Resolved: 02/May/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 4.4.3, 4.2.12, 4.9.0-alpha4 |
| Fix Version/s: | 6.0.0-rc5, 6.1.0-rc0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Andreas Braun | Assignee: | Ted Tuckman |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | query-director-triage | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Backwards Compatibility: | Minor Change | ||||||||||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||||||||||
| Backport Requested: |
v6.0
|
||||||||||||||||||||||||||||||||
| Sprint: | QO 2022-04-04, QO 2022-04-18, QO 2022-05-02, QO 2022-05-16 | ||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||
| Description |
|
While investigating the behaviour as part of To test, I've created a collection with data and created a view based on an empty pipeline:
I've come up with the following calls to distinct:
Most of the cases look the same (except for different result ordering which we can ignore), but the last case differs:
Looking at the pipeline generated, we can see that documentArray.1.x produces three $unwind stages:
This is incorrect, as documentArray.1 should not unwind documentArray first, but rather use $arrayElemAt to. This modified aggregation pipeline produces the same result as the corresponding distinct command:
I was able to reproduce this in 4.2.12, 4.4.3, and 4.9.0-alpha4. It is likely that this also affects previous versions which I didn't have on hand to test. |
| Comments |
| Comment by Githook User [ 04/May/22 ] |
|
Author: {'name': 'Ted Tuckman', 'email': 'ted.tuckman@mongodb.com', 'username': 'TedTuckman'}Message: |
| Comment by Githook User [ 04/May/22 ] |
|
Author: {'name': 'Ted Tuckman', 'email': 'ted.tuckman@mongodb.com', 'username': 'TedTuckman'}Message: |
| Comment by Githook User [ 28/Apr/22 ] |
|
Author: {'name': 'Ted Tuckman', 'email': 'ted.tuckman@mongodb.com', 'username': 'TedTuckman'}Message: |
| Comment by Githook User [ 28/Apr/22 ] |
|
Author: {'name': 'Ted Tuckman', 'email': 'ted.tuckman@mongodb.com', 'username': 'TedTuckman'}Message: |
| Comment by Kyle Suarez [ 16/Mar/21 ] |
|
After re-reading the description more closely I am sending this ticket back to QE Triage to see if we would consider an approach similar to the one in |