-
Notifications
You must be signed in to change notification settings - Fork 104
Address issues with arithmetic, mathematical functions for money/smallmoney #3797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: BABEL_5_X_DEV
Are you sure you want to change the base?
Address issues with arithmetic, mathematical functions for money/smallmoney #3797
Conversation
Pull Request Test Coverage Report for Build 15497840812Details
💛 - Coveralls |
if (adder != (int64) adder) | ||
{ | ||
ereport(ERROR, | ||
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), | ||
errmsg("fixeddecimal out of range"))); | ||
/* ensure compiler realizes we mustn't reach the division (gcc bug) */ | ||
PG_RETURN_NULL(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition and the below condition where we check overflow are required in the following scenario -
When arg2 = INT64_MAX, adder itself overflows and the existing overflow check condition assumes that the adder was always negative. Hence, we first check if the adder overflows and terminate if it does.
if (subtractor != (int64) subtractor) | ||
{ | ||
ereport(ERROR, | ||
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), | ||
errmsg("fixeddecimal out of range"))); | ||
/* ensure compiler realizes we mustn't reach the division (gcc bug) */ | ||
PG_RETURN_NULL(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SImilarly, if arg2 = INT64_MAX, this leads to subtractor overflow and becomes -ve and the overflow check is not correct because it assumes that the arg2 is -ve.
/* | ||
division with values > FIXEDDECIMAL_MAX lead to overflow | ||
in T-SQL | ||
*/ | ||
if (arg1 > FIXEDDECIMAL_MAX) | ||
{ | ||
ereport(ERROR, | ||
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), | ||
errmsg("fixeddecimal out of range"))); | ||
/* ensure compiler realizes we mustn't reach the division (gcc bug) */ | ||
PG_RETURN_NULL(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a TSQL behaviour which we did not respect previously. This condition takes care of the same.
numeric#!#datetime#!#datetime#!#bigint#!#int#!#smallint#!#smallint#!#money#!#datetime#!#varchar#!#datetime#!#bigint | ||
100.50#!#1900-04-11 12:00:00.0#!#1900-04-11 12:00:00.0#!#1000#!#100#!#10#!#1#!#100.5000#!#1900-01-01 00:00:00.0#!#0A1A2A3A4-B1B2-C1C2-D1D2-E1E2E3E4E5E6#!#<NULL>#!#0 | ||
numeric#!#datetime#!#smallmoney#!#bigint#!#int#!#smallint#!#smallint#!#money#!#bit#!#varchar#!#datetime#!#bigint | ||
100.50#!#1900-04-11 12:00:00.0#!#100.5000#!#1000#!#100#!#10#!#1#!#100.5000#!#0#!#0A1A2A3A4-B1B2-C1C2-D1D2-E1E2E3E4E5E6#!#<NULL>#!#0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here the changes are because we introduced new operators for bit. Now, bit + smallmoney results into smallmoney, which previously resulted into datetime and bit + bit results into bit which previously resulted into datetime.
contrib/babelfishpg_common/sql/upgrades/babelfish_common_helper--5.2.0--5.3.0.sql
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,2845 @@ | |||
-- Create test tables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will also need to create prepare and verify test file for this. Upgrade tests should include
- Create views in prepare to cover all operators we are fixing.
- Performance - create a table in prepare with money small money datatype. in verify ensure that index scan is picked for queries on these tables when the predicate has this operator. We can also keep changing the type on one end of the operator.
create table t (id int small money)
create index idx on t(id)
SELECT * FROM t WHERE id (some_operator) (different data types)
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
62ee33e
to
de3d86e
Compare
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
Signed-off-by: Ayush Shah <[email protected]>
Description
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).
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
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 -
NA
Major version upgrade tests -
NA
Performance tests -
NA
Tooling impact -
NA
Client tests -
NA
Check List
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.