[SERVER-60203] Translation of the groupBy expression of a sugared $group is unimplemented Created: 24/Sep/21  Updated: 27/Sep/21  Resolved: 27/Sep/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: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-60239 $group with $and expression fails Closed
Related
related to SERVER-60261 Update comments on $coerceToBool-rela... Closed
related to SERVER-58954 Refactor and unify the code to optimi... Backlog
is related to SERVER-60226 Ban sugared $group stages from being ... Closed
Operating System: ALL
Steps To Reproduce:

A minimal repro for $bucket:

> db.t.insert({a: 1, b: 2})
> db.t.aggregate([{$bucket: {"groupBy": {$and: ["$a", 2]}, boundaries: [0, 1], default: 1}}])

Notice that $bucket without an $and for the groupBy does not produce the error and group can be pushed down and executes correctly,

db.t.aggregate([{$bucket: {"groupBy": "$a", boundaries: [false, true], default: 1}}])

A minimal repro for $sortByCount:

> db.t.aggregate([{$sortByCount: {$and: ["$a", 1]}}])

Sprint: QE 2021-10-04
Participants:

 Description   

The aggregation wildcard fuzzer has exposed a MONGO_UNREACHABLE bug when translating $bucket, $bucketAuto, $sortByGroup's groupBy expression.

The failures for $bucket was a result of these pipelines:

https://logkeeper.mongodb.org/lobster/build/3218f424f7bfc378c1aeed2e8c01dae2/test/614d0ffc54f248035df638c2#bookmarks=0%2C2475&l=1&shareLine=2366

https://logkeeper.mongodb.org/lobster/build/a714767abbebc38d460080c8b03b49f3/test/614d107df84ae83a60f5e1b1#bookmarks=0%2C33378&l=1&shareLine=33244

The failures for $bucketAuto are a result of these pipelines:

https://logkeeper.mongodb.org/lobster/build/2890947a1c22915b1a495afee4235393/test/614d0fa2f84ae83a60f5768a#bookmarks=0%2C2074&l=1&shareLine=1967

https://logkeeper.mongodb.org/lobster/build/2890947a1c22915b1a495afee4235393/test/614d0fa2f84ae83a60f5768a#bookmarks=0%2C2074&l=1&shareLine=1967

The failures for a $sortByCount:
https://logkeeper.mongodb.org/lobster/build/83b786208feaef88d667eb01de92fe49/test/614d104054f248035df657f5#bookmarks=0%2C10597&l=1



 Comments   
Comment by Yoon Soo Kim [ 27/Sep/21 ]

eric.cox, Agreed and closed as a dup of SERVER-60239.

Comment by Eric Cox (Inactive) [ 27/Sep/21 ]

yoonsoo.kim I believe this ticket can be closed because we fixed this in https://github.com/10gen/mongo/pull/898. I opened up SERVER-60239. It looks like the same problem. That's the one wildcard fuzzer failure I witnessed after my build for SERVER-60101.

Comment by Eric Cox (Inactive) [ 24/Sep/21 ]

For $bucket and $sortByCount if the groupBy expression is an $and, $or, or $not of $and $or the groupBy expression is translated to $coerceToBool in the classic engine,

{
			"$group" : {
				"_id" : {
					"$coerceToBool" : [
						"$a"
					]
				},
				"count" : {
					"$sum" : {
						"$const" : 1
					}
				}
			}
		},

Running an example in the classic engine this works because the classic engine evaluates $coerceToBool

MongoDB Enterprise > db.t.aggregate([{$sortByCount: {$and: [“$a”, 1]}}])
{ “_id” : true, “count” : 1 }

This causes the translation flow to go down an unimplemented path when translating ExpressionCoerceToBool in the SBE expression stage builder. I saw some work was done in SERVER-57749 to make sure optimizations are done before we decide to use SBE or the Classic engine, but maybe $bucket, $bucketAuto happens somewhere outside this path?

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