Skip to content

Commit

Permalink
Implement READ_STRING_FIELD_NULL serializable read function.
Browse files Browse the repository at this point in the history
When there is "" string, we need also to palloc memory in OidAssignment.

Authored-by: Zhang Wenchao zwcpostgres@gmail.com
  • Loading branch information
wenchaozhang-123 authored and my-ship-it committed Aug 7, 2024
1 parent 90bbe2f commit d0add48
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/backend/nodes/readfast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/test/regress/expected/gp_types.out
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ SELECT * FROM dml_bitvarying ORDER BY 1;
00
(1 row)

CREATE TYPE size_t AS enum('');
--
-- Interval
--
Expand Down Expand Up @@ -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
--------
Expand Down
4 changes: 4 additions & 0 deletions src/test/regress/sql/gp_types.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
--
Expand Down Expand Up @@ -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;

0 comments on commit d0add48

Please sign in to comment.