From 191aae34189594314042299f50309a1de3574be9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 15 Jan 2024 11:23:39 +0100 Subject: [PATCH v2 2/4] Remove custom _jumbleRangeTblEntry() This is part of an effort to reduce the number of special cases in the automatically generated node support functions. RangeTblEntry has a custom jumble function. This was probably just carried over from the pg_stat_statements-specific code without any detailed review. For example, the "inh" field is documented to be valid in all RTEs, but it's only jumbled for RTE_RELATION. The "lateral" field isn't looked at at all. I wouldn't be surprised if there are more cases like this. This patch removes _jumbleRangeTblEntry() and instead adds per-field query_jumble_ignore annotations to approximately match the behavior of the previous custom code. The pg_stat_statements test suite has some coverage of this. It gets rid of switch on rtekind; this should be technically correct, since we do the equal and copy functions like this also. So for example the "inh" field is now considered in each case. But it leaves "lateral" alone. Probably, several of these new query_jumble_ignore should actually be dropped because the code was wrong before. Discussion: https://www.postgresql.org/message-id/flat/4b27fc50-8cd6-46f5-ab20-88dbaadca645@eisentraut.org --- src/backend/nodes/queryjumblefuncs.c | 48 ---------------------------- src/include/nodes/parsenodes.h | 42 ++++++++++++------------ 2 files changed, 21 insertions(+), 69 deletions(-) diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c index e489bfceb56..7accd7b6242 100644 --- a/src/backend/nodes/queryjumblefuncs.c +++ b/src/backend/nodes/queryjumblefuncs.c @@ -347,51 +347,3 @@ _jumbleA_Const(JumbleState *jstate, Node *node) } } } - -static void -_jumbleRangeTblEntry(JumbleState *jstate, Node *node) -{ - RangeTblEntry *expr = (RangeTblEntry *) node; - - JUMBLE_FIELD(rtekind); - switch (expr->rtekind) - { - case RTE_RELATION: - JUMBLE_FIELD(relid); - JUMBLE_NODE(tablesample); - JUMBLE_FIELD(inh); - break; - case RTE_SUBQUERY: - JUMBLE_NODE(subquery); - break; - case RTE_JOIN: - JUMBLE_FIELD(jointype); - break; - case RTE_FUNCTION: - JUMBLE_NODE(functions); - break; - case RTE_TABLEFUNC: - JUMBLE_NODE(tablefunc); - break; - case RTE_VALUES: - JUMBLE_NODE(values_lists); - break; - case RTE_CTE: - - /* - * Depending on the CTE name here isn't ideal, but it's the only - * info we have to identify the referenced WITH item. - */ - JUMBLE_STRING(ctename); - JUMBLE_FIELD(ctelevelsup); - break; - case RTE_NAMEDTUPLESTORE: - JUMBLE_STRING(enrname); - break; - case RTE_RESULT: - break; - default: - elog(ERROR, "unrecognized RTE kind: %d", (int) expr->rtekind); - break; - } -} diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 648b6197502..d377f16a72b 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -1018,7 +1018,7 @@ typedef enum RTEKind typedef struct RangeTblEntry { - pg_node_attr(custom_read_write, custom_query_jumble) + pg_node_attr(custom_read_write) NodeTag type; @@ -1062,16 +1062,16 @@ typedef struct RangeTblEntry * tables to be invalidated if the underlying table is altered. */ Oid relid; /* OID of the relation */ - char relkind; /* relation kind (see pg_class.relkind) */ - int rellockmode; /* lock level that query requires on the rel */ + char relkind pg_node_attr(query_jumble_ignore); /* relation kind (see pg_class.relkind) */ + int rellockmode pg_node_attr(query_jumble_ignore); /* lock level that query requires on the rel */ struct TableSampleClause *tablesample; /* sampling info, or NULL */ - Index perminfoindex; + Index perminfoindex pg_node_attr(query_jumble_ignore); /* * Fields valid for a subquery RTE (else NULL): */ Query *subquery; /* the sub-query */ - bool security_barrier; /* is from security_barrier view? */ + bool security_barrier pg_node_attr(query_jumble_ignore); /* is from security_barrier view? */ /* * Fields valid for a join RTE (else NULL/zero): @@ -1117,17 +1117,17 @@ typedef struct RangeTblEntry * joinleftcols/joinrighttcols. */ JoinType jointype; /* type of join */ - int joinmergedcols; /* number of merged (JOIN USING) columns */ - List *joinaliasvars; /* list of alias-var expansions */ - List *joinleftcols; /* left-side input column numbers */ - List *joinrightcols; /* right-side input column numbers */ + int joinmergedcols pg_node_attr(query_jumble_ignore); /* number of merged (JOIN USING) columns */ + List *joinaliasvars pg_node_attr(query_jumble_ignore); /* list of alias-var expansions */ + List *joinleftcols pg_node_attr(query_jumble_ignore); /* left-side input column numbers */ + List *joinrightcols pg_node_attr(query_jumble_ignore); /* right-side input column numbers */ /* * join_using_alias is an alias clause attached directly to JOIN/USING. It * is different from the alias field (below) in that it does not hide the * range variables of the tables being joined. */ - Alias *join_using_alias; + Alias *join_using_alias pg_node_attr(query_jumble_ignore); /* * Fields valid for a function RTE (else NIL/zero): @@ -1138,7 +1138,7 @@ typedef struct RangeTblEntry * expandRTE(). */ List *functions; /* list of RangeTblFunction nodes */ - bool funcordinality; /* is this called WITH ORDINALITY? */ + bool funcordinality pg_node_attr(query_jumble_ignore); /* is this called WITH ORDINALITY? */ /* * Fields valid for a TableFunc RTE (else NULL): @@ -1155,7 +1155,7 @@ typedef struct RangeTblEntry */ char *ctename; /* name of the WITH list item */ Index ctelevelsup; /* number of query levels up */ - bool self_reference; /* is this a recursive self-reference? */ + bool self_reference pg_node_attr(query_jumble_ignore); /* is this a recursive self-reference? */ /* * Fields valid for CTE, VALUES, ENR, and TableFunc RTEs (else NIL): @@ -1175,25 +1175,25 @@ typedef struct RangeTblEntry * all three lists (as well as an empty-string entry in eref). Testing * for zero coltype is the standard way to detect a dropped column. */ - List *coltypes; /* OID list of column type OIDs */ - List *coltypmods; /* integer list of column typmods */ - List *colcollations; /* OID list of column collation OIDs */ + List *coltypes pg_node_attr(query_jumble_ignore); /* OID list of column type OIDs */ + List *coltypmods pg_node_attr(query_jumble_ignore); /* integer list of column typmods */ + List *colcollations pg_node_attr(query_jumble_ignore); /* OID list of column collation OIDs */ /* * Fields valid for ENR RTEs (else NULL/zero): */ char *enrname; /* name of ephemeral named relation */ - Cardinality enrtuples; /* estimated or actual from caller */ + Cardinality enrtuples pg_node_attr(query_jumble_ignore); /* estimated or actual from caller */ /* * Fields valid in all RTEs: */ - Alias *alias; /* user-written alias clause, if any */ - Alias *eref; /* expanded reference names */ - bool lateral; /* subquery, function, or values is LATERAL? */ + Alias *alias pg_node_attr(query_jumble_ignore); /* user-written alias clause, if any */ + Alias *eref pg_node_attr(query_jumble_ignore); /* expanded reference names */ + bool lateral pg_node_attr(query_jumble_ignore); /* subquery, function, or values is LATERAL? */ bool inh; /* inheritance requested? */ - bool inFromCl; /* present in FROM clause? */ - List *securityQuals; /* security barrier quals to apply, if any */ + bool inFromCl pg_node_attr(query_jumble_ignore); /* present in FROM clause? */ + List *securityQuals pg_node_attr(query_jumble_ignore); /* security barrier quals to apply, if any */ } RangeTblEntry; /* -- 2.43.0