[SERVER-69865] Primitive arithmetic operations in SBE promote int64 to decimal128 instead of double Created: 21/Sep/22  Updated: 24/Aug/23  Resolved: 21/Sep/22

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

Type: Bug Priority: Major - P3
Reporter: Ivan Fefer Assignee: Ivan Fefer
Resolution: Declined 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:

1. Run mongod with --setParameter featureFlagSbeFull=true
2. Connect and insert document {"lhs": NumberLong("9000000000000000000")}.
3. db.test.aggregate([{$project: {sum: {$add: ["$lhs", NumberLong("-9000000000000000000")]}}}, {$addFields: {st: {$type: "$sum"}}}])
Found:

{ "_id" : ObjectId("632b0eeab16205c4487fd24e"), "sum" : NumberDecimal("-18000000000000000000"), "st" : "decimal" }

Expected:

{ "_id" : ObjectId("632b0eeab16205c4487fd24e"), "sum" : -18000000000000000000, "st" : "double" }
Participants:

 Description   

Currently if result of primitive arithmetic operation in SBE doesn't fit into int64, it will be promoted to decimal128:
https://github.com/mongodb/mongo/blob/master/src/mongo/db/exec/sbe/values/arith_common.cpp#L144 

This contradicts documentation in some cases: https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/#behavior

We don't want to expose decimal to users unless asked explicitly because it is not supported widely.



 Comments   
Comment by Ivan Fefer [ 21/Sep/22 ]

Currently it is not decided if it is a bug or a feature.
See WRITING-10039

Generated at Thu Feb 08 06:14:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.