[SERVER-61648] $group with $avg in $lookup inner pipeline fails Created: 19/Nov/21  Updated: 22/Nov/21  Resolved: 22/Nov/21

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Eric Cox (Inactive) Assignee: Yoon Soo Kim
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Sprint: QE 2021-11-29
Participants:

 Description   

jstests/sharding/query/sharded_lookup_execution.js fails with an assertion in src/mongo/db/pipeline/accumulator_avg.cpp:62 executing this pipeline (see "assertLookupExecution(pipeline, {comment: "unsharded_to_sharded_cache"}" at sharded_lookup_execution.js:632):
[[ {"$match" : {"customer" : "Alice"}}, {"$unwind" : "$products"}, { "$lookup" : { "from" : "reviews", "let" :

{"customer_product_name" : "$products._id"}

, "pipeline" : [ { "$group" : { "_id" : "$product_id", "avg_stars" :

{ "$avg" : "$stars" }

, "name" : { "$first" : "$product_id" } } }, {"$match" : {"$expr" :

{"$eq" : ["$name","$$customer_product_name"]}

}} ], "as" : "avg_review" } }, {"$unwind" : {"path" : "$avg_review", "preserveNullAndEmptyArrays" : true}}, {"$group" : {"_id" : "$_id", "products" : {"$push" : {"_id" : "$products._id","avg_review" : "$avg_review.avg_stars"}}}}]
 

The patch: https://spruce.mongodb.com/version/61956b90e3c3316cd49b37a4/tasks?sorts=STATUS%3AASC%3BBASE_STATUS%3ADESC

Log for this failure:

https://logkeeper.mongodb.org/lobster/build/1d8dc05c673604aecbc4cec148ef4f4f/test/619577cc54f24805af62463d#bookmarks=0%2C25189&l=1&shareLine=22315



 Comments   
Comment by Yoon Soo Kim [ 22/Nov/21 ]

The patched build is based on the commit 73dc221c1d and it enabled $avg accumulator for $group pushdown but it didn't include the sharded $avg logic which is implemented in the commit. So, the $avg is failed in a sharded environment. The issue does not repro anymore after the commit.

Generated at Thu Feb 08 05:52:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.