From 63bd9155b631b16e82781f9a6405ac0ee24cde15 Mon Sep 17 00:00:00 2001
From: Matthias van de Meent <boekewurm+postgres@gmail.com>
Date: Wed, 3 Jan 2024 02:41:23 +0100
Subject: [PATCH v1 4/7] NodeSupport: add some more default markers for various
 fields

This reduces the size of pg_rewrite by a further 14%.
---
 src/include/nodes/parsenodes.h |  8 +++++---
 src/include/nodes/primnodes.h  | 22 ++++++++++++++--------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index b9f122b46c..e11b044b89 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -117,7 +117,8 @@ typedef struct Query
 {
 	NodeTag		type;
 
-	CmdType		commandType;	/* select|insert|update|delete|merge|utility */
+	/* select|insert|update|delete|merge|utility */
+	CmdType		commandType pg_node_attr(default(CMD_SELECT));
 
 	/* where did I come from? */
 	QuerySource querySource pg_node_attr(query_jumble_ignore);
@@ -130,7 +131,7 @@ typedef struct Query
 	uint64		queryId pg_node_attr(equal_ignore, query_jumble_ignore, read_write_ignore, read_as(0));
 
 	/* do I set the command result tag? */
-	bool		canSetTag pg_node_attr(query_jumble_ignore);
+	bool		canSetTag pg_node_attr(query_jumble_ignore, default(true));
 
 	Node	   *utilityStmt;	/* non-null if commandType == CMD_UTILITY */
 
@@ -1235,7 +1236,8 @@ typedef struct RTEPermissionInfo
 
 	Oid			relid;			/* relation OID */
 	bool		inh;			/* separately check inheritance children? */
-	AclMode		requiredPerms;	/* bitmask of required access permissions */
+	/* bitmask of required access permissions, in views usually ACL_SELECT */
+	AclMode		requiredPerms pg_node_attr(default(ACL_SELECT));
 	Oid			checkAsUser;	/* if valid, check access as this role */
 	Bitmapset  *selectedCols;	/* columns needing SELECT permission */
 	Bitmapset  *insertedCols;	/* columns needing INSERT permission */
diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index c9b30b1b0d..acb275900f 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -82,7 +82,7 @@ typedef struct RangeVar
 	char	   *relname;
 
 	/* expand rel by inheritance? recursively act on children? */
-	bool		inh;
+	bool		inh pg_node_attr(default(true));
 
 	/* see RELPERSISTENCE_* in pg_class.h */
 	char		relpersistence;
@@ -126,7 +126,7 @@ typedef struct TableFunc
 	/* nullability flag for each output column */
 	Bitmapset  *notnulls pg_node_attr(query_jumble_ignore);
 	/* counts from 0; -1 if none specified */
-	int			ordinalitycol pg_node_attr(query_jumble_ignore);
+	int			ordinalitycol pg_node_attr(query_jumble_ignore, default(-1));
 	/* token location, or -1 if unknown */
 	int			location;
 } TableFunc;
@@ -237,8 +237,10 @@ typedef struct Var
 	/*
 	 * index of this var's relation in the range table, or
 	 * INNER_VAR/OUTER_VAR/etc
+	 *
+	 * As we start at 1, using that as a default reduces our serialized size.
 	 */
-	int			varno;
+	int			varno pg_node_attr(default(1));
 
 	/*
 	 * attribute number of this var, or zero for all attrs ("whole-row Var")
@@ -269,11 +271,13 @@ typedef struct Var
 	 * varnosyn/varattnosyn are ignored for equality, because Vars with
 	 * different syntactic identifiers are semantically the same as long as
 	 * their varno/varattno match.
+	 * As they're generally the same value as varno/varattno, we refer to
+	 * those fields for initial/default values.
 	 */
 	/* syntactic relation index (0 if unknown) */
-	Index		varnosyn pg_node_attr(equal_ignore, query_jumble_ignore);
+	Index		varnosyn pg_node_attr(equal_ignore, query_jumble_ignore, default_ref(varno));
 	/* syntactic attribute number */
-	AttrNumber	varattnosyn pg_node_attr(equal_ignore, query_jumble_ignore);
+	AttrNumber	varattnosyn pg_node_attr(equal_ignore, query_jumble_ignore, default_ref(varattno));
 
 	/* token location, or -1 if unknown */
 	int			location;
@@ -1763,8 +1767,10 @@ typedef struct CoerceToDomain
 	int32		resulttypmod pg_node_attr(query_jumble_ignore, default(-1));
 	/* OID of collation, or InvalidOid if none */
 	Oid			resultcollid pg_node_attr(query_jumble_ignore);
-	/* how to display this node */
-	CoercionForm coercionformat pg_node_attr(query_jumble_ignore);
+	/* how to display this node.
+	 * This node usually only remains after explicit cast, so that's chosen as
+	 * the default. */
+	CoercionForm coercionformat pg_node_attr(query_jumble_ignore, default(COERCE_EXPLICIT_CAST));
 	int			location;		/* token location, or -1 if unknown */
 } CoerceToDomain;
 
@@ -1975,7 +1981,7 @@ typedef struct TargetEntry
 typedef struct RangeTblRef
 {
 	NodeTag		type;
-	int			rtindex;
+	int			rtindex pg_node_attr(default(1));
 } RangeTblRef;
 
 /*----------
-- 
2.40.1

