[DOCS-14835] DOCS-14835: Investigate changes in SERVER-59785: [SBE] Change $concatArrays to not short-circuit on null Created: 01/Oct/21  Updated: 31/Jan/24

Status: Backlog
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: 5.1.0-rc0

Type: Task Priority: Major - P3
Reporter: Backlog - Core Eng Program Management Team Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: backlog, feature
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-59785 [SBE] Change $concatArrays to not sho... Closed
Participants:
Days since reply: 2 years, 18 weeks, 5 days ago

 Description   
Downstream Change Summary

This change makes it so that SBE does not short circuit on null. That is, it evaluates all of its arguments before checking whether they are null or arrays.

Description of Linked Ticket

In SBE, for almost all aggregate operators, all of the operator's arguments are evaluated first before doing typechecking or anything else. This was an intentional design decision.

From what I can tell, the only aggregate operators that intentionally have "short-circuit" style behavior are as follows:

  • $and - Short-circuits evaluation of the remaining arguments when an argument evaluates to false (or something that when coerced to boolean will produce "false")
  • $or - Short-circuits evaluation of the remaining arguments when an argument evaluates to true (or something that when coerced to boolean will produce "true")
  • $switch - Short-circuits evaluation of the remaining case/then's when a case evaluates to true (or something that when coerced to boolean will produce "true")
  • $ifNull - Short-circuits evaluation of the remaining arguments when an argument evaluates to a value that is not null/missing

Aside from the operators listed above, unless there is a specific reason, each aggregate operator's arguments should be evaluated first before doing anything else.

I noticed that the SBE implementation of $concatArrays seems to exhibit "short-circuit on null" behavior. Here is an example that demonstrates this:

> db.adminCommand({setParameter: 1, internalQueryEnableSlotBasedExecutionEngine: true});
{ "was" : false, "ok" : 1 }
 
> db.c.find()
{_id: 1, a: null, b: "foo"}
 
> db.c.aggregate([{$project: {x: {$concatArrays: [[1,2], "$a", {$add: [1,"$b"]}]}}}])
{_id: 1, x: null}

The goal of this task is to determine if $concatArrays in SBE should evaluate all of its arguments first before doing typechecking or anything else, and if so, to update the SBE implementation of $concatArrays accordingly.



 Comments   
Comment by PM Bot [ 01/Oct/21 ]

Downstream changes updated for upstream SERVER-59785:
This change makes it so that SBE does not short circuit on null. That is, it evaluates all of its arguments before checking whether they are null or arrays.

Generated at Thu Feb 08 08:11:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.