Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement READ_STRING_FIELD_NULL serializable read function. #553

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
wenchaozhang-123 marked this conversation as resolved.
Show resolved Hide resolved
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;
Loading