Skip to content

Address issues with arithmetic, mathematical functions for money/smallmoney#3865

Merged
jsudrik merged 1 commit intobabelfish-for-postgresql:BABEL_4_X_DEVfrom
ayushdsh:smallmoney-issues-fix-4x
Jun 20, 2025
Merged

Address issues with arithmetic, mathematical functions for money/smallmoney#3865
jsudrik merged 1 commit intobabelfish-for-postgresql:BABEL_4_X_DEVfrom
ayushdsh:smallmoney-issues-fix-4x

Conversation

@ayushdsh
Copy link
Copy Markdown
Contributor

@ayushdsh ayushdsh commented Jun 20, 2025

Description

Cherry-pick from 5_X_DEV
Original PR: #3797
Handling overflow and incorrect outputs in case of certain money and smallmoney arithmetic and math functions.

There were certain issues found both w.r.t overflow handling and certain functions and operations giving incorrect result for money and smallmoney datatype. This commit addresses those issues.

Issue #1: Overflow of smallmoney arithmetic leading to TDS hang.
Issue #2: Unhandled overflow cases leading to incorrect output.
Issue #3: Fixeddecimal operators being resolved for smallmoney functions and operations leading to incorrect results.

In this commit, we have added new functions for all smallmoney operators and fixed certain overflows with money (fixeddecimal).

New operators added -

  1. arithmetic operators for bit
    a. bit and float operators
    b. bit and smallmoney operators
    c. bit and bit operators.

The reason to introduce bit,bit and bit,float operators is because once we introduced bit,smallmoney; certain operators did not remain unique - like bit, bit and bit, float.
Previously, their output was datetime which was also not valid. Hence, we've corrected the output and introduced these operators.

New functions added -

  1. All arithmetic functions for smallmoney
    a. smallmoney and int2, int4 and int8
    b. smallmoney and smallmoney
  2. power, ceiling and floor functions for fixeddecimal

Update

  • we will not be introducing bit, bit operators

Issues Resolved

BABEL-5745, BABEL-5757, BABEL-5756, BABEL-5747, BABEL-5754

Test Scenarios Covered

Note: testcases are imported from PR-3568

  • Use case based -

    • All arithmetic and math functions for money and smallmoney
      • with all types of operands and vice-versa
  • Boundary conditions -

    • All boundary conditions for overflow
  • Arbitrary inputs -

    • Certain arbritrary input tests added
  • Negative test cases -

    • Overflow conditions checked which were previously causing protocol hang.
  • Minor version upgrade tests -

    • dependency tests for all the new operators and functions
  • Major version upgrade tests -

    • dependency tests for all the new operators and functions
  • Performance tests -

    • NA
  • Tooling impact -

    • NA
  • Client tests -

    • NA

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…smallmoney arithmetic and math functions.

There were certain issues found both w.r.t overflow handling and certain functions and operations giving incorrect result for money and smallmoney datatype. This commit addresses those issues.

Issue babelfish-for-postgresql#1: Overflow of smallmoney arithmetic leading to TDS hang.
Issue babelfish-for-postgresql#2: Unhandled overflow cases leading to incorrect output.
Issue babelfish-for-postgresql#3: Fixeddecimal operators being resolved for smallmoney functions and operations leading to incorrect results.

Task: BABEL-5745, BABEL-5757, BABEL-5756, BABEL-5747, BABEL-5754

Signed-off-by: Ayush Shah <ayushdsh@amazon.com>
@coveralls
Copy link
Copy Markdown
Collaborator

Pull Request Test Coverage Report for Build 15777264714

Details

  • 405 of 439 (92.26%) changed or added relevant lines in 3 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 75.729%

Changes Missing Coverage Covered Lines Changed/Added Lines %
contrib/babelfishpg_money/fixeddecimal.c 51 53 96.23%
contrib/babelfishpg_common/src/bit.c 117 124 94.35%
contrib/babelfishpg_money/smallmoney.c 237 262 90.46%
Files with Coverage Reduction New Missed Lines %
contrib/babelfishpg_money/fixeddecimal.c 2 78.51%
Totals Coverage Status
Change from base Build 15776758268: 0.2%
Covered Lines: 49182
Relevant Lines: 64945

💛 - Coveralls

@ayushdsh ayushdsh marked this pull request as ready for review June 20, 2025 12:03
Copy link
Copy Markdown
Contributor

@jsudrik jsudrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical changes to already merged PR #3797 in 5x branch. Approved.

@jsudrik jsudrik merged commit a8af654 into babelfish-for-postgresql:BABEL_4_X_DEV Jun 20, 2025
48 checks passed
sharathbp pushed a commit to amazon-aurora/babelfish_extensions that referenced this pull request Sep 22, 2025
…smallmoney arithmetic and math functions. (babelfish-for-postgresql#3865)

There were certain issues found both w.r.t overflow handling and certain functions and operations giving incorrect result for money and smallmoney datatype. This commit addresses those issues.

Issue #1: Overflow of smallmoney arithmetic leading to TDS hang.
Issue #2: Unhandled overflow cases leading to incorrect output.
Issue #3: Fixeddecimal operators being resolved for smallmoney functions and operations leading to incorrect results.

Task: BABEL-5745, BABEL-5757, BABEL-5756, BABEL-5747, BABEL-5754

Signed-off-by: Ayush Shah <ayushdsh@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants