From d0add48089f13bbaa31284ac62ab88eb79806671 Mon Sep 17 00:00:00 2001 From: zhangwenchao <656540940@qq.com> Date: Fri, 2 Aug 2024 15:29:24 +0800 Subject: [PATCH] Implement READ_STRING_FIELD_NULL serializable read function. When there is "" string, we need also to palloc memory in OidAssignment. Authored-by: Zhang Wenchao zwcpostgres@gmail.com --- src/backend/nodes/readfast.c | 19 ++++++++++++++++++- src/test/regress/expected/gp_types.out | 2 ++ src/test/regress/sql/gp_types.sql | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/backend/nodes/readfast.c b/src/backend/nodes/readfast.c index daed3060d50..204027c75e5 100644 --- a/src/backend/nodes/readfast.c +++ b/src/backend/nodes/readfast.c @@ -119,9 +119,26 @@ } \ var = nn; } +#define READ_STRING_VAR_NULL(var) \ + { int slen; char * nn = NULL; \ + memcpy(&slen, read_str_ptr, sizeof(int)); \ + read_str_ptr+=sizeof(int); \ + if (slen>0) { \ + nn = palloc(slen+1); \ + memcpy(nn,read_str_ptr,slen); \ + read_str_ptr+=(slen); nn[slen]='\0'; \ + } \ + if (slen==0) { \ + nn = palloc(1); \ + nn[0] = '\0'; \ + } \ + var = nn; } + /* Read a character-string field */ #define READ_STRING_FIELD(fldname) READ_STRING_VAR(local_node->fldname) +#define READ_STRING_FIELD_NULL(fldname) READ_STRING_VAR_NULL(local_node->fldname) + /* Read a parse location field (and throw away the value, per notes above) */ #define READ_LOCATION_FIELD(fldname) READ_INT_FIELD(fldname) @@ -892,7 +909,7 @@ _readOidAssignment(void) READ_LOCALS(OidAssignment); READ_OID_FIELD(catalog); - READ_STRING_FIELD(objname); + READ_STRING_FIELD_NULL(objname); READ_OID_FIELD(namespaceOid); READ_OID_FIELD(keyOid1); READ_OID_FIELD(keyOid2); diff --git a/src/test/regress/expected/gp_types.out b/src/test/regress/expected/gp_types.out index 101f69dfa3d..45bde01bd96 100644 --- a/src/test/regress/expected/gp_types.out +++ b/src/test/regress/expected/gp_types.out @@ -41,6 +41,7 @@ SELECT * FROM dml_bitvarying ORDER BY 1; 00 (1 row) +CREATE TYPE size_t AS enum(''); -- -- Interval -- @@ -425,6 +426,7 @@ SELECT float8in(float8out(a)) FROM FLOATS ORDER BY a; COPY FLOATS TO '/tmp/floats'; TRUNCATE FLOATS; COPY FLOATS FROM '/tmp/floats'; +DROP TYPE size_t; SELECT * FROM FLOATS ORDER BY a; a -------- diff --git a/src/test/regress/sql/gp_types.sql b/src/test/regress/sql/gp_types.sql index dd8c6efa1e1..53d4d7cdff9 100644 --- a/src/test/regress/sql/gp_types.sql +++ b/src/test/regress/sql/gp_types.sql @@ -23,6 +23,8 @@ SELECT * FROM dml_bitvarying ORDER BY 1; UPDATE dml_bitvarying SET a = '000'; SELECT * FROM dml_bitvarying ORDER BY 1; +CREATE TYPE size_t AS enum(''); + -- -- Interval -- @@ -172,4 +174,6 @@ COPY FLOATS TO '/tmp/floats'; TRUNCATE FLOATS; COPY FLOATS FROM '/tmp/floats'; +DROP TYPE size_t; + SELECT * FROM FLOATS ORDER BY a;