[SERVER-62111] Inconsistent results between SBE and Classical engines for queries with $dateAdd on invalid inputs Created: 16/Dec/21  Updated: 27/Oct/23  Resolved: 17/Dec/21

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

Type: Bug Priority: Major - P3
Reporter: Irina Yatsenko (Inactive) Assignee: Irina Yatsenko (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Operating System: ALL
Steps To Reproduce:

collection: {_id:0}

query:
find(
{},
{x: {$dateAdd: {startDate: "$date",unit: "second",amount: {$indexOfCP: ["foo", "$str", 0]},}}}
)

Results:
classic:

{ "_id" : 0, "x" : null }

sbe: "code" : 5075301, "errmsg" : "Executor error during find command :: caused by :: $indexOfCP substring must resolve to a string"

Sprint: QE 2021-12-27
Participants:
Linked BF Score: 141

 Comments   
Comment by Irina Yatsenko (Inactive) [ 17/Dec/21 ]

That is, the difference in behavior in this ticket is by design. Relaxing the fuzzers to take this into account has been fixed per TIG-3637.

Comment by Irina Yatsenko (Inactive) [ 17/Dec/21 ]

It has been decided in prior similar precedents that the following should be SBE's canonical behavior:
1. only the "logical" style operators $and, $or, $switch and $ifNull will perform short-circuit evaluation
2. other operators don't do short-circuiting and maintain strict left-to-right evaluation
3. if certain inputs are null and all inputs are valid, output null

This means that occasionally it's possible for a query to succeed in one engine and fail in another and this shouldn't be considered a bug.

Comment by Irina Yatsenko (Inactive) [ 16/Dec/21 ]

Note, if the projection clause is modified to {x: {$dateAdd: {startDate: new Date(), unit: "second", amount: {$indexOfCP: ["foo", "$str", 0]},}}}, the classic engine starts returning "errmsg" : "Executor error during find command :: caused by :: $indexOfCP requires a string as the second argument, found: missing", so I suspect, when the field for startDate is missing, the classic engine doesn't evaluate the `amount` but SBE still does...

Confirmed: in ExpressionDateArithmetics::evaluate() the startDate is evaluated first, and if missing it returns immediately w/o evaluating the rest of the args.

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