Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-69865

Primitive arithmetic operations in SBE promote int64 to decimal128 instead of double

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Declined
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None
    • ALL
    • Hide

      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" }
      Show
      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" }

    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.

      Attachments

        Activity

          People

            ivan.fefer@mongodb.com Ivan Fefer
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: