[SERVER-66812] Incorrect $group/$project optimization analysis can cause incorrect results for strange queries Created: 26/May/22 Updated: 29/Oct/23 Resolved: 07/Jun/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 5.3.0, 5.2.0 |
| Fix Version/s: | 6.0.0-rc9, 6.1.0-rc0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Charlie Swanson | Assignee: | Charlie Swanson |
| Resolution: | Fixed | 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 | ||||
| Backport Requested: |
v6.0
|
||||
| Participants: | |||||
| Description |
|
We have some logic to detect when a projection underneath a $group stage is not needed and optimize it away. This analysis has some code that appears to be trying to check for a case like this and avoid removing the projection since it would impact the query results:
Unfortunately it looks like that analysis was implemented incorrectly and instead of checking if the projection provides all the fields that the $group needs, it appears to be checking something different. I think it's whether none of the projection fields are needed by the $group? In any case, there is a demonstrable bug around this optimization that should be fixed. I'll attach a patch to demonstrate. |
| Comments |
| Comment by Githook User [ 08/Jun/22 ] |
|
Author: {'name': 'Charlie Swanson', 'email': 'charlie.swanson@mongodb.com', 'username': 'cswanson310'}Message: (cherry picked from commit 8a3af130c7dba9936b30e17d25dd52a5802658ad) |
| Comment by Githook User [ 06/Jun/22 ] |
|
Author: {'name': 'Charlie Swanson', 'email': 'charlie.swanson@mongodb.com', 'username': 'cswanson310'}Message: |