Skip to content

Commit

Permalink
fix(common): limit min signed int64 value to -9223372036854775807 #1206
Browse files Browse the repository at this point in the history
[summary]
In Tianmu engine:
For int64, -9223372036854775807 is reserved to indicate as `NULL_64` flag, so we limit
min value of int64 to -9223372036854775806.

For int32, -2147483648 is reserved to indicate as `NULL_32` flag, we limit min value of int32
to -2147483647.
  • Loading branch information
hustjieke authored and mergify[bot] committed Mar 6, 2023
1 parent cf31f0a commit bc15bbe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
18 changes: 18 additions & 0 deletions mysql-test/suite/tianmu/r/signed_boundary.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Test signed boundary
#
DROP DATABASE IF EXISTS signed_boundary;
CREATE TABLE int32_(c_max int, c_min int) engine = tianmu;
INSERT INTO int32_ values(-2147483647, 2147483647);
INSERT INTO int32_ values(-2147483648, 2147483647);
ERROR 22003: Out of range[-2147483647, 2147483647] for column 'c_max' value: -2147483648
INSERT INTO int32_ values(-2147483647, 2147483648);
ERROR 22003: Out of range value for column 'c_min' at row 1
DROP TABLE int32_;
CREATE TABLE int64_(c_max bigint, c_min bigint) engine = tianmu;
INSERT INTO int64_ values(-9223372036854775806, 9223372036854775807);
INSERT INTO int64_ values(-9223372036854775807, 9223372036854775807);
ERROR 22003: Out of range[-9223372036854775807, 9223372036854775807] for column 'c_max' value: -9223372036854775807
INSERT INTO int64_ values(-9223372036854775806, 9223372036854775808);
ERROR 22003: Out of range value for column 'c_min' at row 1
DROP TABLE int64_;
27 changes: 27 additions & 0 deletions mysql-test/suite/tianmu/t/signed_boundary.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--source include/have_tianmu.inc

--echo #
--echo # Test signed boundary
--echo #

--disable_warnings
DROP DATABASE IF EXISTS signed_boundary;
--enable_warnings

# int32 limit
CREATE TABLE int32_(c_max int, c_min int) engine = tianmu;
INSERT INTO int32_ values(-2147483647, 2147483647);
--error 1264
INSERT INTO int32_ values(-2147483648, 2147483647);
--error 1264
INSERT INTO int32_ values(-2147483647, 2147483648);
DROP TABLE int32_;

# int64 limit
CREATE TABLE int64_(c_max bigint, c_min bigint) engine = tianmu;
INSERT INTO int64_ values(-9223372036854775806, 9223372036854775807);
--error 1264
INSERT INTO int64_ values(-9223372036854775807, 9223372036854775807);
--error 1264
INSERT INTO int64_ values(-9223372036854775806, 9223372036854775808);
DROP TABLE int64_;
2 changes: 1 addition & 1 deletion storage/tianmu/common/common_definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void PushWarningIfOutOfRange(THD *thd, std::string col_name, int64_t v, int type
PushWarning(thd, Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE,
getErrMsg(col_name, 0, TIANMU_BIGINT_MAX, unsigned_flag, v).c_str());
throw std::exception();
} else if (v > TIANMU_BIGINT_MAX || v < TIANMU_BIGINT_MIN) {
} else if (v > TIANMU_BIGINT_MAX || v <= TIANMU_BIGINT_MIN) {
PushWarning(thd, Sql_condition::SL_WARNING, ER_WARN_DATA_OUT_OF_RANGE,
getErrMsg(col_name, TIANMU_BIGINT_MIN, TIANMU_BIGINT_MAX, unsigned_flag, v).c_str());
throw std::exception();
Expand Down

0 comments on commit bc15bbe

Please sign in to comment.