[SERVER-56083] [SBE] Expressions unsupported in SBE for agg operations prevent SBE engine from being selected even if not pushed down Created: 13/Apr/21  Updated: 29/Oct/23  Resolved: 30/Apr/21

Status: Closed
Project: Core Server
Component/s: Query Execution
Affects Version/s: None
Fix Version/s: 5.0.0-rc0

Type: Improvement Priority: Major - P3
Reporter: David Storch Assignee: Eric Cox (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-56084 [SBE] aggregation_multiversion_fuzzer... Closed
related to SERVER-56498 Remove SBE agg pushdown intergration ... Backlog
Backwards Compatibility: Fully Compatible
Sprint: Query Execution 2021-05-03
Participants:

 Description   

The following example aggregation operation reports explainVersion:"2", indicating that the portion of the query pushed down to the find layer is executing using the SBE engine:

MongoDB Enterprise > db.c.explain().aggregate([{$match: {a: 1}}, {$unwind: "$b"}, {$project: {_id: 0, a: 1, b: 1}}]).explainVersion
2

However, if I modify this aggregate command just slightly to include a $dateToString expression, then the portion of the query pushed down to the find layer falls back to the classic execution engine. This is indicated by explainVersion:"1" in the following example:

MongoDB Enterprise > db.c.explain().aggregate([{$match: {a: 1}}, {$unwind: "$b"}, {$project: {_id: 0, a: 1, b: {$dateToString: {date: "$b"}}}}]).explainVersion
1

Note that the $dateToString expression itself is executing in the DocumentSource layer, since it is not pushed down into $cursor:

MongoDB Enterprise > db.c.explain().aggregate([{$match: {a: 1}}, {$unwind: "$b"}, {$project: {_id: 0, a: 1, b: {$dateToString: {date: "$b"}}}}]).stages
[
	{
		"$cursor" : { ... }
	},
	{
		"$unwind" : {
			"path" : "$b"
		}
	},
	{
		"$project" : {
			"a" : true,
			"b" : {
				"$dateToString" : {
					"date" : "$b"
				}
			},
			"_id" : false
		}
	}
]

Because the $dateToString operation is not pushed down, the $cursor portion of this query is fully supported in SBE. As an improvement, we should change the logic which chooses between the SBE and classic engines so that it allows the SBE engine to be used in scenarios like this.

It looks like the reason for the current behavior is that the value of ExpressionContext::sbeCompatible is set at parse time, before any analysis is done that would determine which part of the query should be implemented by the find subsystem and which part by the agg subsystem.



 Comments   
Comment by Githook User [ 30/Apr/21 ]

Author:

{'name': 'Eric Cox', 'email': 'eric.cox@mongodb.com', 'username': 'ericox'}

Message: SERVER-56083 [SBE] Expressions unsupported in SBE for agg operations prevent SBE engine from being selected even if not pushed down
Branch: master
https://github.com/mongodb/mongo/commit/49f6fcebd3c4a97abcd05c862ad1204eed9d66ef

Comment by Eric Cox (Inactive) [ 29/Apr/21 ]

I re-ran the agg fuzzers with the proposed fix in the CR. The aggregation_wildcard_fuzzer surfaced a failure with $indexOfCP.

https://logkeeper.mongodb.org/lobster/build/2f29f68f6e65e0886b670895313a5dc8/test/6089e5d2904130456a2665e4#bookmarks=0%2C130279%2C130567&l=1

But the failure is related to my fix for TIG-2998.

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