[SERVER-66072] $match sampling and $group aggregation strange behavior Created: 29/Apr/22 Updated: 29/Oct/23 Resolved: 11/Jul/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Query Execution, Query Planning |
| Affects Version/s: | 5.0.8, 5.0.6 |
| Fix Version/s: | 6.0.1, 5.0.11, 6.1.0-rc0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Johan Maupetit | Assignee: | Alya Berciu |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | aggregation, group, sample | ||
| 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, v5.3, v5.0
|
||||||||||||
| Sprint: | QE 2022-06-13, QO 2022-07-11, QO 2022-07-25 | ||||||||||||
| Participants: | |||||||||||||
| Description |
|
I'm using mongodb aggregation pipeline with $sampleRate in order to improve my query performances. I felt on a strange behavior i don't understand ... Here is my aggregation pipeline running on a big collection (1M+ documents) :
When i do this i get approximately two times more documents than when i inverse the $replaceRoot and $sampleRate steps =>
... I don't understand why oO They should give the same number of documents to me. Do you know where i'm failing to understand ? Or is it a bug ? PS : I created a question here : https://stackoverflow.com/questions/72048023/mongodb-aggregate-pipeline-sampling-fail |
| Comments |
| Comment by Githook User [ 29/Jul/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Alya Berciu', 'email': 'alya.berciu@mongodb.com', 'username': 'alyacb'}Message: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 28/Jul/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Alya Berciu', 'email': 'alya.berciu@mongodb.com', 'username': 'alyacb'}Message: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Alya Berciu [ 11/Jul/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Closing as the fix has been merged to master. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 11/Jul/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'Alya Berciu', 'email': 'alya.berciu@mongodb.com', 'username': 'alyacb'}Message: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Johan Maupetit [ 19/Jun/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you mongo team for the informations, have a good luck for fixing this one | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Zixuan Zhuang [ 09/Jun/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you cjbjohan.maupetit@laposte.net for filing this bug ticket. We've determined it was caused by | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Zixuan Zhuang [ 01/Jun/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The root cause is that we generate an incorrect query plan, when $sample is before $replaceRoot, $sample is pushed down to query and performed before $group so that it samples based on original documents instead of grouped documents. This is the plan for correct query (`$replaceRoot` then `$sample`)
This is the plan for wrong query (`$sample` then `$replaceRoot`):
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Chris Kelly [ 23/May/22 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Johan, Thank you for your patience. I've taken a look at your issue and forwarded it to the Query Execution team to investigate further. Christopher |