From b5c04bb6dd5539f4be2dbdfe6bc0f5ebc791b6ca Mon Sep 17 00:00:00 2001 From: wangpingyun <2418191738@qq.com> Date: Thu, 25 Jul 2024 16:00:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B5=AE=E7=82=B9=E6=95=B0?= =?UTF-8?q?=E7=89=B9=E6=AE=8A=E5=80=BC=E6=98=BE=E7=A4=BAGUC=E6=8E=A7?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/gs_guc/cluster_guc.conf | 1 + src/common/backend/utils/adt/float.cpp | 36 +++- src/common/backend/utils/misc/guc/guc_sql.cpp | 11 ++ .../knl/knl_guc/knl_session_attr_sql.h | 1 + .../regress/expected/test_binary_suffix.out | 159 +++++++++++------- src/test/regress/sql/test_binary_suffix.sql | 9 + 6 files changed, 150 insertions(+), 67 deletions(-) diff --git a/src/bin/gs_guc/cluster_guc.conf b/src/bin/gs_guc/cluster_guc.conf index 762256d80..ddfd0467b 100755 --- a/src/bin/gs_guc/cluster_guc.conf +++ b/src/bin/gs_guc/cluster_guc.conf @@ -359,6 +359,7 @@ wdr_snapshot_retention_days|int|1,8|NULL|NULL| wdr_snapshot_query_timeout|int|100,2147483647|s|NULL| enable_wdr_snapshot|bool|0,0|NULL|NULL| enable_set_variable_b_format|bool|0,0|NULL|NULL| +enable_binary_special_o_format|bool|0,0|NULL|NULL| enable_asp|bool|0,0|NULL|NULL| enable_startwith_debug|bool|0,0|NULL|NULL| enable_stmt_track|bool|0,0|NULL|NULL| diff --git a/src/common/backend/utils/adt/float.cpp b/src/common/backend/utils/adt/float.cpp index 0d6a4d74d..01e700c47 100644 --- a/src/common/backend/utils/adt/float.cpp +++ b/src/common/backend/utils/adt/float.cpp @@ -397,18 +397,30 @@ Datum float4out(PG_FUNCTION_ARGS) errno_t rc = EOK; if (isnan(num)) { - rc = strcpy_s(ascii, MAXFLOATWIDTH + 1, "NaN"); + if (u_sess->attr.attr_sql.enable_binary_special_o_format) { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "Nan"); + } else { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "NaN"); + } securec_check_ss(rc, "\0", "\0"); PG_RETURN_CSTRING(ascii); } switch (is_infinite(num)) { case 1: - rc = strcpy_s(ascii, MAXFLOATWIDTH + 1, "Infinity"); + if (u_sess->attr.attr_sql.enable_binary_special_o_format) { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "Inf"); + } else { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "Infinity"); + } securec_check_ss(rc, "\0", "\0"); break; case -1: - rc = strcpy_s(ascii, MAXFLOATWIDTH + 1, "-Infinity"); + if (u_sess->attr.attr_sql.enable_binary_special_o_format) { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "-Inf"); + } else { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "-Infinity"); + } securec_check_ss(rc, "\0", "\0"); break; default: { @@ -627,17 +639,29 @@ Datum float8out(PG_FUNCTION_ARGS) errno_t rc = EOK; if (isnan(num)) { - rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "NaN"); + if (u_sess->attr.attr_sql.enable_binary_special_o_format) { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "Nan"); + } else { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "NaN"); + } securec_check(rc, "\0", "\0"); PG_RETURN_CSTRING(ascii); } switch (is_infinite(num)) { case 1: - rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "Infinity"); + if (u_sess->attr.attr_sql.enable_binary_special_o_format) { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "Inf"); + } else { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "Infinity"); + } securec_check(rc, "\0", "\0"); break; case -1: - rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "-Infinity"); + if (u_sess->attr.attr_sql.enable_binary_special_o_format) { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "-Inf"); + } else { + rc = strcpy_s(ascii, MAXDOUBLEWIDTH + 1, "-Infinity"); + } securec_check(rc, "\0", "\0"); break; default: { diff --git a/src/common/backend/utils/misc/guc/guc_sql.cpp b/src/common/backend/utils/misc/guc/guc_sql.cpp index bd7328666..eeb0c890f 100755 --- a/src/common/backend/utils/misc/guc/guc_sql.cpp +++ b/src/common/backend/utils/misc/guc/guc_sql.cpp @@ -663,6 +663,17 @@ static void InitSqlConfigureNamesBool() NULL, NULL, NULL}, + {{"enable_binary_special_o_format", + PGC_USERSET, + NODE_ALL, + QUERY_TUNING_COST, + gettext_noop("Allows the user to specify the value of a double-precision floating-point parameter."), + NULL}, + &u_sess->attr.attr_sql.enable_binary_special_o_format, + false, + NULL, + NULL, + NULL}, {{"enable_seqscan", PGC_USERSET, NODE_ALL, diff --git a/src/include/knl/knl_guc/knl_session_attr_sql.h b/src/include/knl/knl_guc/knl_session_attr_sql.h index e93f14bbd..12ef618de 100644 --- a/src/include/knl/knl_guc/knl_session_attr_sql.h +++ b/src/include/knl/knl_guc/knl_session_attr_sql.h @@ -127,6 +127,7 @@ typedef struct knl_session_attr_sql { bool enable_light_proxy; bool enable_pbe_optimization; bool enable_cluster_resize; + bool enable_binary_special_o_format; bool lo_compat_privileges; bool quote_all_identifiers; bool enforce_a_behavior; diff --git a/src/test/regress/expected/test_binary_suffix.out b/src/test/regress/expected/test_binary_suffix.out index 3de471e99..829f3d54d 100644 --- a/src/test/regress/expected/test_binary_suffix.out +++ b/src/test/regress/expected/test_binary_suffix.out @@ -433,16 +433,53 @@ ERROR: syntax error at or near "/" LINE 1: SELECT 4.0f / 2.0; ^ set float_suffix_acceptance to on; +SELECT CONCAT('The value is ', TO_CHAR(BINARY_DOUBLE_INFINITY)) AS result; + result +----------------------- + The value is Infinity +(1 row) + +SELECT CONCAT('The value is ', TO_CHAR(-BINARY_DOUBLE_INFINITY)) AS result; + result +------------------------ + The value is -Infinity +(1 row) + +SELECT CONCAT('The value is ', TO_CHAR(-BINARY_DOUBLE_NAN)) AS result; + result +------------------ + The value is NaN +(1 row) + +set enable_binary_special_o_format to on; +SELECT CONCAT('The value is ', TO_CHAR(BINARY_DOUBLE_INFINITY)) AS result; + result +------------------ + The value is Inf +(1 row) + +SELECT CONCAT('The value is ', TO_CHAR(-BINARY_DOUBLE_INFINITY)) AS result; + result +------------------- + The value is -Inf +(1 row) + +SELECT CONCAT('The value is ', TO_CHAR(-BINARY_DOUBLE_NAN)) AS result; + result +------------------ + The value is Nan +(1 row) + SELECT BINARY_DOUBLE_INFINITY; binary_double_infinity ------------------------ - Infinity + Inf (1 row) SELECT BINARY_DOUBLE_NAN; binary_double_nan ------------------- - NaN + Nan (1 row) CREATE TABLE test_table ( @@ -454,7 +491,7 @@ VALUES (1, BINARY_DOUBLE_NAN); SELECT * FROM test_table WHERE float_value = BINARY_DOUBLE_NAN; id | float_value ----+------------- - 1 | NaN + 1 | Nan (1 row) INSERT INTO test_table (id, float_value) @@ -462,75 +499,75 @@ VALUES (2, BINARY_DOUBLE_INFINITY); SELECT * FROM test_table WHERE float_value = BINARY_DOUBLE_INFINITY; id | float_value ----+------------- - 2 | Infinity + 2 | Inf (1 row) SELECT float_value + 1 FROM test_table WHERE id = 1; ?column? ---------- - NaN + Nan (1 row) SELECT float_value * 2 FROM test_table WHERE id = 2; ?column? ---------- - Infinity + Inf (1 row) SELECT * FROM test_table WHERE float_value = BINARY_DOUBLE_NAN OR float_value = BINARY_DOUBLE_INFINITY; id | float_value ----+------------- - 1 | NaN - 2 | Infinity + 1 | Nan + 2 | Inf (2 rows) DROP TABLE test_table; SELECT ABS(binary_double_infinity); - abs ----------- - Infinity + abs +----- + Inf (1 row) SELECT CEIL(binary_double_infinity); - ceil ----------- - Infinity + ceil +------ + Inf (1 row) SELECT SQRT(binary_double_infinity); - sqrt ----------- - Infinity + sqrt +------ + Inf (1 row) SELECT FLOOR(binary_double_infinity); - floor ----------- - Infinity + floor +------- + Inf (1 row) SELECT SQRT(binary_double_infinity); - sqrt ----------- - Infinity + sqrt +------ + Inf (1 row) SELECT EXP(binary_double_infinity); - exp ----------- - Infinity + exp +----- + Inf (1 row) SELECT LOG(binary_double_infinity); - log ----------- - Infinity + log +----- + Inf (1 row) SELECT POWER(binary_double_infinity, 2); - power ----------- - Infinity + power +------- + Inf (1 row) SELECT SIN(binary_double_infinity); @@ -539,55 +576,55 @@ CONTEXT: referenced column: sin SELECT ABS(binary_double_nan); abs ----- - NaN + Nan (1 row) SELECT CEIL(binary_double_nan); ceil ------ - NaN + Nan (1 row) SELECT SQRT(binary_double_nan); sqrt ------ - NaN + Nan (1 row) SELECT FLOOR(binary_double_nan); floor ------- - NaN + Nan (1 row) SELECT SQRT(binary_double_nan); sqrt ------ - NaN + Nan (1 row) SELECT EXP(binary_double_nan); exp ----- - NaN + Nan (1 row) SELECT LOG(binary_double_nan); log ----- - NaN + Nan (1 row) SELECT POWER(binary_double_nan, 2); power ------- - NaN + Nan (1 row) SELECT SIN(binary_double_nan); sin ----- - NaN + Nan (1 row) -- 创建自定义函数 @@ -668,49 +705,49 @@ SELECT (binary_double_infinity > 0.0) OR (binary_double_nan < binary_double_infi SELECT binary_double_infinity + 1.0; -- 返回正无穷大 ?column? ---------- - Infinity + Inf (1 row) SELECT binary_double_nan + 1.0; -- 返回 NaN ?column? ---------- - NaN + Nan (1 row) SELECT binary_double_infinity - binary_double_infinity; -- 返回 NaN ?column? ---------- - NaN + Nan (1 row) SELECT binary_double_nan - 1.0; -- 返回 NaN ?column? ---------- - NaN + Nan (1 row) SELECT binary_double_infinity * binary_double_infinity; -- 返回正无穷大 ?column? ---------- - Infinity + Inf (1 row) SELECT binary_double_nan * 1.0; -- 返回 NaN ?column? ---------- - NaN + Nan (1 row) SELECT binary_double_infinity / binary_double_infinity; -- 返回 NaN ?column? ---------- - NaN + Nan (1 row) SELECT binary_double_nan / 1.0; -- 返回 NaN ?column? ---------- - NaN + Nan (1 row) CREATE TABLE T1(binary_double_nan INT); @@ -718,15 +755,15 @@ INSERT INTO T1 VALUES(1),(2),(3); SELECT binary_double_nan; binary_double_nan ------------------- - NaN + Nan (1 row) SELECT binary_double_nan FROM T1; binary_double_nan ------------------- - NaN - NaN - NaN + Nan + Nan + Nan (3 rows) SELECT T1.binary_double_nan FROM T1; @@ -770,19 +807,19 @@ insert into t1 values(binary_double_nan); select avg(id) from t1; avg ----- - NaN + Nan (1 row) select sum(id) from t1; sum ----- - NaN + Nan (1 row) select max(id) from t1; max ----- - NaN + Nan (1 row) select min(id) from t1; @@ -800,9 +837,9 @@ insert into t1 values(3.14),(10),(15); select binary_double_nan from t1; binary_double_nan ------------------- - NaN - NaN - NaN + Nan + Nan + Nan (3 rows) select t1.binary_double_nan from t1; @@ -820,7 +857,7 @@ insert into t1 values (100,9); select * from t1; binary_double_infinity | id ------------------------+---- - Infinity | 10 + Inf | 10 100 | 9 (2 rows) @@ -832,7 +869,7 @@ select * from t1 where binary_double_infinity = 100; select * from t1 where binary_double_infinity = binary_double_infinity; binary_double_infinity | id ------------------------+---- - Infinity | 10 + Inf | 10 100 | 9 (2 rows) diff --git a/src/test/regress/sql/test_binary_suffix.sql b/src/test/regress/sql/test_binary_suffix.sql index 213d83405..b25346156 100644 --- a/src/test/regress/sql/test_binary_suffix.sql +++ b/src/test/regress/sql/test_binary_suffix.sql @@ -157,6 +157,15 @@ SELECT 4.0f / 2.0; set float_suffix_acceptance to on; + +SELECT CONCAT('The value is ', TO_CHAR(BINARY_DOUBLE_INFINITY)) AS result; +SELECT CONCAT('The value is ', TO_CHAR(-BINARY_DOUBLE_INFINITY)) AS result; +SELECT CONCAT('The value is ', TO_CHAR(-BINARY_DOUBLE_NAN)) AS result; +set enable_binary_special_o_format to on; +SELECT CONCAT('The value is ', TO_CHAR(BINARY_DOUBLE_INFINITY)) AS result; +SELECT CONCAT('The value is ', TO_CHAR(-BINARY_DOUBLE_INFINITY)) AS result; +SELECT CONCAT('The value is ', TO_CHAR(-BINARY_DOUBLE_NAN)) AS result; + SELECT BINARY_DOUBLE_INFINITY; SELECT BINARY_DOUBLE_NAN;