From a2f46ae6830d47c3bea15e8bfb4765810da1b8c0 Mon Sep 17 00:00:00 2001 From: lukeman Date: Fri, 25 Aug 2023 20:06:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86issue:=E5=85=BC=E5=AE=B9B?= =?UTF-8?q?=E5=BA=93=E6=A8=A1=E5=BC=8F=E4=B8=8B=EF=BC=8Cbigint=20unsigned?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=BD=ACbigint=E7=B1=BB=E5=9E=8B=E9=83=A8?= =?UTF-8?q?=E5=88=86=E7=BB=93=E6=9E=9C=E4=B8=8Emysql=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dolphin/expected/none_strict_warning.out | 61 ++++++------- contrib/dolphin/expected/signed_cast.out | 85 +++++++++---------- contrib/dolphin/expected/uint_cast.out | 7 +- contrib/dolphin/expected/uint_sql_mode.out | 8 +- .../dolphin/plugin_utils/adt/unsigned_int.cpp | 18 ---- contrib/dolphin/sql/none_strict_warning.sql | 6 +- 6 files changed, 78 insertions(+), 107 deletions(-) diff --git a/contrib/dolphin/expected/none_strict_warning.out b/contrib/dolphin/expected/none_strict_warning.out index 75db18606..d1cd66c7a 100644 --- a/contrib/dolphin/expected/none_strict_warning.out +++ b/contrib/dolphin/expected/none_strict_warning.out @@ -791,16 +791,12 @@ insert ignore into test_uint4 values(-129::uint8); WARNING: int unsigned out of range CONTEXT: referenced column: c1 ---- ui8toi8 ----- over int8_max 严格模式error,非严格模式warning,结果int8_max +---- over int8_max 正整数溢出为对应的负整数 insert into test_int8 values(9223372036854775808::uint8); -ERROR: bigint out of range -CONTEXT: referenced column: c1 insert into test_int8 values(-9223372036854775809::uint8); ERROR: bigint unsigned out of range CONTEXT: referenced column: c1 insert ignore into test_int8 values(9223372036854775808::uint8); -WARNING: bigint out of range -CONTEXT: referenced column: c1 insert ignore into test_int8 values(-9223372036854775808::uint8); ERROR: bigint unsigned out of range CONTEXT: referenced column: c1 @@ -1062,15 +1058,16 @@ select * from test_int4; (8 rows) select * from test_int8; - c1 ---------------------- - 2147483647 - 32767 - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 -(6 rows) + c1 +---------------------- + 2147483647 + 32767 + 9223372036854775807 + 9223372036854775807 + 9223372036854775807 + -9223372036854775808 + -9223372036854775808 +(7 rows) select * from test_uint1; c1 @@ -2013,16 +2010,12 @@ insert ignore into test_uint4 values(-129::uint8); WARNING: int unsigned out of range CONTEXT: referenced column: c1 ---- ui8toi8 ----- over int8_max 严格模式error,非严格模式warning,结果int8_max +---- over int8_max 正整数溢出为对应的负整数 insert into test_int8 values(9223372036854775808::uint8); -WARNING: bigint out of range -CONTEXT: referenced column: c1 insert into test_int8 values(-9223372036854775809::uint8); ERROR: bigint unsigned out of range CONTEXT: referenced column: c1 insert ignore into test_int8 values(9223372036854775808::uint8); -WARNING: bigint out of range -CONTEXT: referenced column: c1 insert ignore into test_int8 values(-9223372036854775808::uint8); ERROR: bigint unsigned out of range CONTEXT: referenced column: c1 @@ -2407,21 +2400,21 @@ select * from test_int4; (22 rows) select * from test_int8; - c1 ---------------------- - 9223372036854775807 - 2147483647 - 2147483647 - 32767 - 32767 - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 + c1 +---------------------- + 9223372036854775807 + 2147483647 + 2147483647 + 32767 + 32767 + 9223372036854775807 + 9223372036854775807 + 9223372036854775807 + 9223372036854775807 + 9223372036854775807 + 9223372036854775807 + -9223372036854775808 + -9223372036854775808 (13 rows) select * from test_uint1; diff --git a/contrib/dolphin/expected/signed_cast.out b/contrib/dolphin/expected/signed_cast.out index 6c865200f..342afdaba 100644 --- a/contrib/dolphin/expected/signed_cast.out +++ b/contrib/dolphin/expected/signed_cast.out @@ -55,8 +55,11 @@ select cast(1e30::uint8 as signed); ERROR: bigint unsigned out of range CONTEXT: referenced column: int8 select cast(18446744073709551615::uint8 as signed); -ERROR: bigint out of range -CONTEXT: referenced column: int8 + int8 +------ + -1 +(1 row) + select cast(18446744073709551616::uint8 as signed); ERROR: bigint unsigned out of range CONTEXT: referenced column: int8 @@ -67,8 +70,11 @@ select cast(9223372036854775807::uint8 as signed); (1 row) select cast(9223372036854775808::uint8 as signed); -ERROR: bigint out of range -CONTEXT: referenced column: int8 + int8 +---------------------- + -9223372036854775808 +(1 row) + select cast(-9223372036854775808::uint8 as signed); ERROR: bigint unsigned out of range CONTEXT: referenced column: int8 @@ -434,8 +440,13 @@ select * from test_uint8; (3 rows) select cast(a as signed) from test_uint8; -ERROR: bigint out of range -CONTEXT: referenced column: a + a +---------------------- + 9223372036854775807 + -9223372036854775808 + -1 +(3 rows) + ----- bit drop table if exists test_bit; NOTICE: table "test_bit" does not exist, skipping @@ -568,39 +579,31 @@ select cast(123::uint8 as signed); select cast(1e30::uint8 as int8); WARNING: bigint unsigned out of range CONTEXT: referenced column: int8 -WARNING: bigint out of range -CONTEXT: referenced column: int8 - int8 ---------------------- - 9223372036854775807 + int8 +------ + -1 (1 row) select cast(1e30::uint8 as signed); WARNING: bigint unsigned out of range CONTEXT: referenced column: int8 -WARNING: bigint out of range -CONTEXT: referenced column: int8 - int8 ---------------------- - 9223372036854775807 + int8 +------ + -1 (1 row) select cast(18446744073709551615::uint8 as signed); -WARNING: bigint out of range -CONTEXT: referenced column: int8 - int8 ---------------------- - 9223372036854775807 + int8 +------ + -1 (1 row) select cast(18446744073709551616::uint8 as signed); WARNING: bigint unsigned out of range CONTEXT: referenced column: int8 -WARNING: bigint out of range -CONTEXT: referenced column: int8 - int8 ---------------------- - 9223372036854775807 + int8 +------ + -1 (1 row) select cast(9223372036854775807::uint8 as signed); @@ -610,11 +613,9 @@ select cast(9223372036854775807::uint8 as signed); (1 row) select cast(9223372036854775808::uint8 as signed); -WARNING: bigint out of range -CONTEXT: referenced column: int8 - int8 ---------------------- - 9223372036854775807 + int8 +---------------------- + -9223372036854775808 (1 row) select cast(-9223372036854775808::uint8 as signed); @@ -1174,20 +1175,14 @@ select * from test_uint8; (6 rows) select cast(a as signed) from test_uint8; -WARNING: bigint out of range -CONTEXT: referenced column: a -WARNING: bigint out of range -CONTEXT: referenced column: a -WARNING: bigint out of range -CONTEXT: referenced column: a - a ---------------------- - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 - 9223372036854775807 - 0 - 0 + a +---------------------- + 9223372036854775807 + -9223372036854775808 + -1 + -1 + 0 + 0 (6 rows) ----- bit diff --git a/contrib/dolphin/expected/uint_cast.out b/contrib/dolphin/expected/uint_cast.out index 9b885e6e1..cbb11bd75 100644 --- a/contrib/dolphin/expected/uint_cast.out +++ b/contrib/dolphin/expected/uint_cast.out @@ -1153,8 +1153,11 @@ select 9223372036854775807::uint8::int8; (1 row) select 18446744073709551615::uint8::int8; -ERROR: bigint out of range -CONTEXT: referenced column: int8 + int8 +------ + -1 +(1 row) + select 18446744073709551615::uint8::float4; float4 ------------- diff --git a/contrib/dolphin/expected/uint_sql_mode.out b/contrib/dolphin/expected/uint_sql_mode.out index dd0c107f9..59e2badef 100644 --- a/contrib/dolphin/expected/uint_sql_mode.out +++ b/contrib/dolphin/expected/uint_sql_mode.out @@ -1476,11 +1476,9 @@ select 9223372036854775807::uint8::int8; (1 row) select 18446744073709551615::uint8::int8; -WARNING: bigint out of range -CONTEXT: referenced column: int8 - int8 ---------------------- - 9223372036854775807 + int8 +------ + -1 (1 row) select 18446744073709551615::uint8::float4; diff --git a/contrib/dolphin/plugin_utils/adt/unsigned_int.cpp b/contrib/dolphin/plugin_utils/adt/unsigned_int.cpp index 09f1bca78..9a097b6a5 100644 --- a/contrib/dolphin/plugin_utils/adt/unsigned_int.cpp +++ b/contrib/dolphin/plugin_utils/adt/unsigned_int.cpp @@ -2679,24 +2679,6 @@ Datum ui4toui8(PG_FUNCTION_ARGS) Datum ui8toi8(PG_FUNCTION_ARGS) { uint64 arg1 = PG_GETARG_UINT64(0); - int64 result; - - /* - * Does it fit in an int64? Avoid assuming that we have handy constants - * defined for the range boundaries, instead test for overflow by - * reverse-conversion. - */ - result = (int64)arg1; - - if (arg1 > LONG_MAX) { - if (fcinfo->can_ignore || !SQL_MODE_STRICT()) { - ereport(WARNING, (errmsg("bigint out of range"))); - PG_RETURN_INT64((int64)LONG_MAX); - } else { - ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("bigint out of range"))); - } - } - PG_RETURN_INT64((int64)arg1); } diff --git a/contrib/dolphin/sql/none_strict_warning.sql b/contrib/dolphin/sql/none_strict_warning.sql index 68b893674..6c1367aa9 100644 --- a/contrib/dolphin/sql/none_strict_warning.sql +++ b/contrib/dolphin/sql/none_strict_warning.sql @@ -429,7 +429,7 @@ insert ignore into test_uint4 values(4294967296::uint8); insert ignore into test_uint4 values(-129::uint8); ---- ui8toi8 ----- over int8_max 严格模式error,非严格模式warning,结果int8_max +---- over int8_max 正整数溢出为对应的负整数 insert into test_int8 values(9223372036854775808::uint8); insert into test_int8 values(-9223372036854775809::uint8); insert ignore into test_int8 values(9223372036854775808::uint8); @@ -979,7 +979,7 @@ insert ignore into test_uint4 values(4294967296::uint8); insert ignore into test_uint4 values(-129::uint8); ---- ui8toi8 ----- over int8_max 严格模式error,非严格模式warning,结果int8_max +---- over int8_max 正整数溢出为对应的负整数 insert into test_int8 values(9223372036854775808::uint8); insert into test_int8 values(-9223372036854775809::uint8); insert ignore into test_int8 values(9223372036854775808::uint8); @@ -1100,4 +1100,4 @@ select * from test_uint2; select * from test_uint4; select * from test_uint8; drop schema none_strict_warning_test cascade; -reset current_schema; \ No newline at end of file +reset current_schema; -- Gitee