You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ch...@apache.org on 2025/09/24 13:57:29 UTC

(cloudberry) branch cbdb-postgres-merge updated: Fix compile errors for read functions

This is an automated email from the ASF dual-hosted git repository.

chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/cbdb-postgres-merge by this push:
     new a6f1f3718ea Fix compile errors for read functions
a6f1f3718ea is described below

commit a6f1f3718ea8feb0493d720fd96e7045f3e8d7da
Author: Jinbao Chen <ch...@gmail.com>
AuthorDate: Wed Sep 24 21:57:14 2025 +0800

    Fix compile errors for read functions
---
 src/backend/nodes/outfast.c          | 106 +++++++++++++++++-----------
 src/backend/nodes/outfuncs.c         | 132 ++++++++++++++++++++++-------------
 src/backend/nodes/readfast.c         |  33 +++++++--
 src/backend/nodes/readfuncs.c        |  15 ++--
 src/backend/nodes/readfuncs_common.c |  96 ++++++++++---------------
 5 files changed, 220 insertions(+), 162 deletions(-)

diff --git a/src/backend/nodes/outfast.c b/src/backend/nodes/outfast.c
index de8169c7b9e..bfc244b904a 100644
--- a/src/backend/nodes/outfast.c
+++ b/src/backend/nodes/outfast.c
@@ -545,47 +545,71 @@ _outAExpr(StringInfo str, A_Expr *node)
 }
 
 static void
-_outValue(StringInfo str, Value *value)
+_outInteger(StringInfo str, const Integer *node)
 {
+	int16 vt = T_Integer;
+	appendBinaryStringInfo(str, (const char *)&vt, sizeof(int16));
+	appendBinaryStringInfo(str, (const char *)&node->ival, sizeof(long));
+}
+
 
-	int16 vt = value->type;
+static void
+_outFloat(StringInfo str, const Float *node)
+{
+	int16 vt = T_Float;
+	int slen;
+
+	appendBinaryStringInfo(str, (const char *) &vt, sizeof(int16));
+	slen = (node->fval != NULL ? strlen(node->fval) : 0);
+	appendBinaryStringInfo(str, (const char *)&slen, sizeof(int));
+	if (slen > 0)
+		appendBinaryStringInfo(str, node->fval, slen);
+}
+
+static void
+_outBoolean(StringInfo str, const Boolean *node)
+{
+	int16 vt = T_Boolean;
 	appendBinaryStringInfo(str, (const char *)&vt, sizeof(int16));
-	switch (value->type)
-	{
-		case T_Integer:
-			appendBinaryStringInfo(str, (const char *)&value->val.ival, sizeof(long));
-			break;
-		case T_Float:
-		case T_String:
-		case T_BitString:
-			{
-				int slen = (value->val.str != NULL ? strlen(value->val.str) : 0);
-				appendBinaryStringInfo(str, (const char *)&slen, sizeof(int));
-				if (slen > 0)
-					appendBinaryStringInfo(str, value->val.str, slen);
-			}
-			break;
-		case T_Null:
-			/* nothing to do */
-			break;
-		default:
-			elog(ERROR, "unrecognized node type: %d", (int) value->type);
-			break;
-	}
+	appendBinaryStringInfo(str, (const char *)&node->boolval, sizeof(long));
 }
 
+
+static void
+_outString(StringInfo str, const String *node)
+{
+	int16 vt = T_String;
+	int slen;
+
+	appendBinaryStringInfo(str, (const char *) &vt, sizeof(int16));
+	slen = (node->sval != NULL ? strlen(node->sval) : 0);
+	appendBinaryStringInfo(str, (const char *)&slen, sizeof(int));
+	if (slen > 0)
+		appendBinaryStringInfo(str, node->sval, slen);
+}
+
+static void
+_outBitString(StringInfo str, const BitString *node)
+{
+	int16 vt = T_BitString;
+	int slen;
+
+	appendBinaryStringInfo(str, (const char *) &vt, sizeof(int16));
+	slen = (node->bsval != NULL ? strlen(node->bsval) : 0);
+	appendBinaryStringInfo(str, (const char *)&slen, sizeof(int));
+	if (slen > 0)
+		appendBinaryStringInfo(str, node->bsval, slen);
+}
+
+
 static void
 _outAConst(StringInfo str, A_Const *node)
 {
 	WRITE_NODE_TYPE("A_CONST");
 
-	if (node->isnull)
-		appendStringInfoString(str, " NULL");
-	else
-	{
-		appendStringInfoString(str, " :val ");
-		outNode(str, &node->val);
-	}
+	if (!node->isnull)
+		_outNode(str, &node->val);
+
 	WRITE_LOCATION_FIELD(location);
 }
 
@@ -876,14 +900,18 @@ _outNode(StringInfo str, void *obj)
 	}
 	else if (IsA(obj, List) ||IsA(obj, IntList) || IsA(obj, OidList))
 		_outList(str, obj);
-	else if (IsA(obj, Integer) ||
-			 IsA(obj, Float) ||
-			 IsA(obj, String) ||
-			 IsA(obj, Null) ||
-			 IsA(obj, BitString))
-	{
-		_outValue(str, obj);
-	}
+	else if (IsA(obj, Integer))
+		_outInteger(str, (Integer *) obj);
+	else if (IsA(obj, Float))
+		_outFloat(str, (Float *) obj);
+	else if (IsA(obj, Boolean))
+		_outBoolean(str, (Boolean *) obj);
+	else if (IsA(obj, String))
+		_outString(str, (String *) obj);
+	else if (IsA(obj, BitString))
+		_outBitString(str, (BitString *) obj);
+	else if (IsA(obj, Bitmapset))
+		outBitmapset(str, (Bitmapset *) obj);
 	else
 	{
 		switch (nodeTag(obj))
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index f34620f400a..51fd5f00df4 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -216,6 +216,11 @@ outToken(StringInfo str, const char *s)
 		appendStringInfoString(str, "<>");
 		return;
 	}
+	if (*s == '\0')
+	{
+		appendStringInfoString(str, "\"\"");
+		return;
+	}
 
 	/*
 	 * Look for characters or patterns that are treated specially by read.c
@@ -249,6 +254,13 @@ outChar(StringInfo str, char c)
 {
 	char		in[2];
 
+	/* Traditionally, we've represented \0 as <>, so keep doing that */
+	if (c == '\0')
+	{
+		appendStringInfoString(str, "<>");
+		return;
+	}
+
 	in[0] = c;
 	in[1] = '\0';
 
@@ -261,7 +273,7 @@ outChar(StringInfo str, char c)
 static void
 outDouble(StringInfo str, double d)
 {
-	char            buf[DOUBLE_SHORTEST_DECIMAL_LEN];
+	char		buf[DOUBLE_SHORTEST_DECIMAL_LEN];
 
 	double_to_shortest_decimal_buf(d, buf);
 	appendStringInfoString(str, buf);
@@ -278,6 +290,8 @@ _outList(StringInfo str, const List *node)
 		appendStringInfoChar(str, 'i');
 	else if (IsA(node, OidList))
 		appendStringInfoChar(str, 'o');
+	else if (IsA(node, XidList))
+		appendStringInfoChar(str, 'x');
 
 	foreach(lc, node)
 	{
@@ -296,6 +310,8 @@ _outList(StringInfo str, const List *node)
 			appendStringInfo(str, " %d", lfirst_int(lc));
 		else if (IsA(node, OidList))
 			appendStringInfo(str, " %u", lfirst_oid(lc));
+		else if (IsA(node, XidList))
+			appendStringInfo(str, " %u", lfirst_xid(lc));
 		else
 			elog(ERROR, "unrecognized list node type: %d",
 				 (int) node->type);
@@ -3850,46 +3866,6 @@ _outAExpr(StringInfo str, const A_Expr *node)
 	WRITE_LOCATION_FIELD(location);
 }
 
-static void
-_outValue(StringInfo str, const Value *value)
-{
-	switch (value->type)
-	{
-		case T_Integer:
-			appendStringInfo(str, "%d", value->val.ival);
-			break;
-		case T_Float:
-
-			/*
-			 * We assume the value is a valid numeric literal and so does not
-			 * need quoting.
-			 */
-			appendStringInfoString(str, value->val.str);
-			break;
-		case T_String:
-
-			/*
-			 * We use outToken to provide escaping of the string's content,
-			 * but we don't want it to do anything with an empty string.
-			 */
-			appendStringInfoChar(str, '"');
-			if (value->val.str[0] != '\0')
-				outToken(str, value->val.str);
-			appendStringInfoChar(str, '"');
-			break;
-		case T_BitString:
-			/* internal representation already has leading 'b' */
-			appendStringInfoString(str, value->val.str);
-			break;
-		case T_Null:
-			/* this is seen only within A_Const, not in transformed trees */
-			appendStringInfoString(str, "NULL");
-			break;
-		default:
-			elog(ERROR, "unrecognized node type: %d", (int) value->type);
-			break;
-	}
-}
 #endif /* COMPILING_BINARY_FUNCS */
 
 static void
@@ -3925,6 +3901,56 @@ _outRawStmt(StringInfo str, const RawStmt *node)
 }
 
 #ifndef COMPILING_BINARY_FUNCS
+
+
+static void
+_outInteger(StringInfo str, const Integer *node)
+{
+	appendStringInfo(str, "%d", node->ival);
+}
+
+static void
+_outFloat(StringInfo str, const Float *node)
+{
+	/*
+	 * We assume the value is a valid numeric literal and so does not need
+	 * quoting.
+	 */
+	appendStringInfoString(str, node->fval);
+}
+
+static void
+_outBoolean(StringInfo str, const Boolean *node)
+{
+	appendStringInfoString(str, node->boolval ? "true" : "false");
+}
+
+static void
+_outString(StringInfo str, const String *node)
+{
+	/*
+	 * We use outToken to provide escaping of the string's content, but we
+	 * don't want it to convert an empty string to '""', because we're putting
+	 * double quotes around the string already.
+	 */
+	appendStringInfoChar(str, '"');
+	if (node->sval[0] != '\0')
+		outToken(str, node->sval);
+	appendStringInfoChar(str, '"');
+}
+
+static void
+_outBitString(StringInfo str, const BitString *node)
+{
+	/*
+	 * The lexer will always produce a string starting with 'b' or 'x'.  There
+	 * might be characters following that that need escaping, but outToken
+	 * won't escape the 'b' or 'x'.  This is relied on by nodeTokenType.
+	 */
+	Assert(node->bsval[0] == 'b' || node->bsval[0] == 'x');
+	outToken(str, node->bsval);
+}
+
 static void
 _outAConst(StringInfo str, const A_Const *node)
 {
@@ -4259,16 +4285,22 @@ outNode(StringInfo str, const void *obj)
 
 	if (obj == NULL)
 		appendStringInfoString(str, "<>");
-	else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList))
+	else if (IsA(obj, List) || IsA(obj, IntList) || IsA(obj, OidList) ||
+			 IsA(obj, XidList))
 		_outList(str, obj);
-	else if (IsA(obj, Integer) ||
-			 IsA(obj, Float) ||
-			 IsA(obj, String) ||
-			 IsA(obj, BitString))
-	{
-		/* nodeRead does not want to see { } around these! */
-		_outValue(str, obj);
-	}
+	/* nodeRead does not want to see { } around these! */
+	else if (IsA(obj, Integer))
+		_outInteger(str, (Integer *) obj);
+	else if (IsA(obj, Float))
+		_outFloat(str, (Float *) obj);
+	else if (IsA(obj, Boolean))
+		_outBoolean(str, (Boolean *) obj);
+	else if (IsA(obj, String))
+		_outString(str, (String *) obj);
+	else if (IsA(obj, BitString))
+		_outBitString(str, (BitString *) obj);
+	else if (IsA(obj, Bitmapset))
+		outBitmapset(str, (Bitmapset *) obj);
 	else
 	{
 		appendStringInfoChar(str, '{');
diff --git a/src/backend/nodes/readfast.c b/src/backend/nodes/readfast.c
index 887f9eae433..2e344796aa4 100644
--- a/src/backend/nodes/readfast.c
+++ b/src/backend/nodes/readfast.c
@@ -463,15 +463,38 @@ _readAConst(void)
 {
 	READ_LOCALS(A_Const);
 
-	READ_ENUM_FIELD(val.type, NodeTag);
+	READ_ENUM_FIELD(val.node.type, NodeTag);
 
-	switch (local_node->val.type)
+	switch (local_node->val.node.type)
 	{
 		case T_Integer:
-			memcpy(&local_node->val.val.ival, read_str_ptr, sizeof(long)); read_str_ptr+=sizeof(long);
+			memcpy(&local_node->val.ival.ival, read_str_ptr, sizeof(long)); read_str_ptr+=sizeof(long);
+			break;
+		case T_Boolean:
+			memcpy(&local_node->val.boolval.boolval, read_str_ptr, sizeof(long)); read_str_ptr+=sizeof(long);
 			break;
 		case T_Float:
+		{
+			int slen; char * nn;
+			memcpy(&slen, read_str_ptr, sizeof(int));
+			read_str_ptr+=sizeof(int);
+			nn = palloc(slen+1);
+			memcpy(nn,read_str_ptr,slen);
+			nn[slen] = '\0';
+			local_node->val.fval.fval = nn; read_str_ptr+=slen;
+		}
+			break;
 		case T_String:
+		{
+			int slen; char * nn;
+			memcpy(&slen, read_str_ptr, sizeof(int));
+			read_str_ptr+=sizeof(int);
+			nn = palloc(slen+1);
+			memcpy(nn,read_str_ptr,slen);
+			nn[slen] = '\0';
+			local_node->val.sval.sval = nn; read_str_ptr+=slen;
+		}
+			break;
 		case T_BitString:
 		{
 			int slen; char * nn;
@@ -480,7 +503,7 @@ _readAConst(void)
 			nn = palloc(slen+1);
 			memcpy(nn,read_str_ptr,slen);
 			nn[slen] = '\0';
-			local_node->val.val.str = nn; read_str_ptr+=slen;
+			local_node->val.bsval.bsval = nn; read_str_ptr+=slen;
 		}
 			break;
 	 	case T_Null:
@@ -935,7 +958,7 @@ _readDynamicSeqScan(void)
 {
 	READ_LOCALS(DynamicSeqScan);
 
-	ReadCommonScan(&local_node->seqscan);
+	ReadCommonScan(&local_node->seqscan.scan);
 	READ_NODE_FIELD(partOids);
 	READ_NODE_FIELD(part_prune_info);
 	READ_NODE_FIELD(join_prune_paramids);
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index 636e79d1cf4..5d9ae29a830 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -101,7 +101,7 @@
 #define READ_UINT64_FIELD(fldname) \
 	token = pg_strtok(&length);		/* skip :fldname */ \
 	token = pg_strtok(&length);		/* get field value */ \
-	local_node->fldname = pg_strtouint64(token, NULL, 10)
+	local_node->fldname = strtou64(token, NULL, 10)
 
 /* Read a long integer field (anything written as ":fldname %ld") */
 #define READ_LONG_FIELD(fldname) \
@@ -1453,10 +1453,15 @@ _readRangeTblEntry(void)
 			READ_CHAR_FIELD(relkind);
 			READ_INT_FIELD(rellockmode);
 			READ_NODE_FIELD(tablesample);
+			READ_UINT_FIELD(perminfoindex);
 			break;
 		case RTE_SUBQUERY:
 			READ_NODE_FIELD(subquery);
 			READ_BOOL_FIELD(security_barrier);
+			READ_OID_FIELD(relid);
+			READ_CHAR_FIELD(relkind);
+			READ_INT_FIELD(rellockmode);
+			READ_UINT_FIELD(perminfoindex);
 			break;
 		case RTE_JOIN:
 			READ_ENUM_FIELD(jointype, JoinType);
@@ -1523,12 +1528,6 @@ _readRangeTblEntry(void)
 	READ_BOOL_FIELD(lateral);
 	READ_BOOL_FIELD(inh);
 	READ_BOOL_FIELD(inFromCl);
-	READ_UINT_FIELD(requiredPerms);
-	READ_OID_FIELD(checkAsUser);
-	READ_BITMAPSET_FIELD(selectedCols);
-	READ_BITMAPSET_FIELD(insertedCols);
-	READ_BITMAPSET_FIELD(updatedCols);
-	READ_BITMAPSET_FIELD(extraUpdatedCols);
 	READ_NODE_FIELD(securityQuals);
 
 	READ_BOOL_FIELD(forceDistRandom);
@@ -1911,7 +1910,7 @@ _readSeqScan(void)
 {
 	READ_LOCALS_NO_FIELDS(SeqScan);
 
-	ReadCommonScan(local_node);
+	ReadCommonScan(&local_node->scan);
 
 	READ_DONE();
 }
diff --git a/src/backend/nodes/readfuncs_common.c b/src/backend/nodes/readfuncs_common.c
index 92f9828c1d1..db259750bfd 100644
--- a/src/backend/nodes/readfuncs_common.c
+++ b/src/backend/nodes/readfuncs_common.c
@@ -43,65 +43,40 @@ _readAConst(void)
 {
 	READ_LOCALS(A_Const);
 
-	/* skip " :val " */
+	/* We expect either NULL or :val here */
 	token = pg_strtok(&length);
-	if (length != 4 || token[0] != ':' || token[1] != 'v')
-		elog(ERROR,"Unable to understand A_CONST node \"%.30s\"", token);
-
-	token = pg_strtok(&length);
-	token = debackslash(token,length);
-	local_node->val.type = T_String;
-
-	if (token[0] == '"')
-	{
-		local_node->val.val.str = palloc(length - 1);
-		strncpy(local_node->val.val.str , token+1, strlen(token)-2);
-		local_node->val.val.str[strlen(token)-2] = '\0';
-	}
-	else if (length > 2 && (token[0] == 'b'|| token[0] == 'B') && (token[1] == '\'' || token[1] == '"'))
-	{
-		local_node->val.type = T_BitString;
-		local_node->val.val.str = palloc(length+1);
-		strncpy(local_node->val.val.str , token, length);
-		local_node->val.val.str[length] = '\0';
-	}
+	if (length == 4 && strncmp(token, "NULL", 4) == 0)
+		local_node->isnull = true;
 	else
 	{
-		bool isInt = true;
-		bool isFloat = true;
-		int i = 0;
-		if (token[i] == ' ')
-			i++;
-		if (token[i] == '-' || token[i] == '+')
-			i++;
-		for (; i < length; i++)
-	 	   if (token[i] < '0' || token[i] > '9')
-	 	   {
-	 	   	 isInt = false;
-	 	   	 if (token[i] != '.' && token[i] != 'e' && token[i] != 'E' && token[i] != '+' && token[i] != '-')
-	 	   	 	isFloat = false;
-	 	   }
-	 	if (isInt)
-		{
-			local_node->val.type = T_Integer;
-			local_node->val.val.ival = atol(token);
-		}
-		else if (isFloat)
-		{
-			local_node->val.type = T_Float;
-			local_node->val.val.str = palloc(length + 1);
-			strcpy(local_node->val.val.str , token);
-		}
-		else
+		union ValUnion *tmp = nodeRead(NULL, 0);
+
+		/* To forestall valgrind complaints, copy only the valid data */
+		switch (nodeTag(tmp))
 		{
-			elog(ERROR,"Deserialization problem:  A_Const not string, bitstring, float, or int");
-			local_node->val.val.str = palloc(length + 1);
-			strcpy(local_node->val.val.str , token);
+			case T_Integer:
+				memcpy(&local_node->val, tmp, sizeof(Integer));
+				break;
+			case T_Float:
+				memcpy(&local_node->val, tmp, sizeof(Float));
+				break;
+			case T_Boolean:
+				memcpy(&local_node->val, tmp, sizeof(Boolean));
+				break;
+			case T_String:
+				memcpy(&local_node->val, tmp, sizeof(String));
+				break;
+			case T_BitString:
+				memcpy(&local_node->val, tmp, sizeof(BitString));
+				break;
+			default:
+				elog(ERROR, "unrecognized node type: %d",
+					 (int) nodeTag(tmp));
+				break;
 		}
 	}
 
-    /* CDB: 'location' field is not serialized */
-    local_node->location = -1;
+	READ_LOCATION_FIELD(location);
 
 	READ_DONE();
 }
@@ -363,9 +338,9 @@ _readAlterPublicationStmt()
 
 	READ_STRING_FIELD(pubname);
 	READ_NODE_FIELD(options);
-	READ_NODE_FIELD(tables);
+	READ_NODE_FIELD(pubobjects);
 	READ_BOOL_FIELD(for_all_tables);
-	READ_ENUM_FIELD(tableAction, DefElemAction);
+	READ_ENUM_FIELD(action, AlterPublicationAction);
 
 	READ_DONE();
 }
@@ -903,7 +878,7 @@ _readCreatePublicationStmt()
 
 	READ_STRING_FIELD(pubname);
 	READ_NODE_FIELD(options);
-	READ_NODE_FIELD(tables);
+	READ_NODE_FIELD(pubobjects);
 	READ_BOOL_FIELD(for_all_tables);
 
 	READ_DONE();
@@ -1260,7 +1235,7 @@ _readGrantRoleStmt(void)
 	READ_NODE_FIELD(granted_roles);
 	READ_NODE_FIELD(grantee_roles);
 	READ_BOOL_FIELD(is_grant);
-	READ_BOOL_FIELD(admin_opt);
+	READ_NODE_FIELD(opt);
 	READ_NODE_FIELD(grantor);
 	READ_ENUM_FIELD(behavior, DropBehavior);
     Assert(local_node->behavior <= DROP_CASCADE);
@@ -1346,10 +1321,11 @@ _readIndexStmt(void)
 	READ_NODE_FIELD(excludeOpNames);
 	READ_STRING_FIELD(idxcomment);
 	READ_OID_FIELD(indexOid);
-	READ_OID_FIELD(oldNode);
+	READ_OID_FIELD(oldNumber);
 	READ_UINT_FIELD(oldCreateSubid);
-	READ_UINT_FIELD(oldFirstRelfilenodeSubid);
+	READ_UINT_FIELD(oldFirstRelfilelocatorSubid);
 	READ_BOOL_FIELD(unique);
+	READ_BOOL_FIELD(nulls_not_distinct);
 	READ_BOOL_FIELD(primary);
 	READ_BOOL_FIELD(isconstraint);
 	READ_BOOL_FIELD(deferrable);
@@ -1472,7 +1448,7 @@ _readPartitionSpec(void)
 {
 	READ_LOCALS(PartitionSpec);
 
-	READ_STRING_FIELD(strategy);
+	READ_ENUM_FIELD(strategy, PartitionStrategy);
 	READ_NODE_FIELD(partParams);
 	READ_LOCATION_FIELD(location);
 
@@ -1568,7 +1544,7 @@ _readRestrictInfo(void)
 	READ_BOOL_FIELD(leakproof);
 	READ_ENUM_FIELD(has_volatile, VolatileFunctionStatus);
 	READ_UINT_FIELD(security_level);
-	WRITE_INT_FIELD(num_base_rels);
+	READ_INT_FIELD(num_base_rels);
 	READ_BOOL_FIELD(contain_outer_query_references);
 	READ_BITMAPSET_FIELD(clause_relids);
 	READ_BITMAPSET_FIELD(required_relids);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org