v2-0004-WIP-Remove-custom-RangeTblEntry-node-read-write-i.patch
text/plain
Filename: v2-0004-WIP-Remove-custom-RangeTblEntry-node-read-write-i.patch
Type: text/plain
Part: 3
Patch
Format: format-patch
Series: patch v2-0004
Subject: WIP: Remove custom RangeTblEntry node read/write implementations
| File | + | − |
|---|---|---|
| src/backend/nodes/outfuncs.c | 0 | 80 |
| src/backend/nodes/readfuncs.c | 0 | 92 |
| src/include/nodes/parsenodes.h | 8 | 4 |
From 3f8c3217e529e2b5a07e9ea226fc71eb33e485ad Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Mon, 15 Jan 2024 11:23:39 +0100
Subject: [PATCH v2 4/4] WIP: Remove custom RangeTblEntry node read/write
implementations
This is part of an effort to reduce the number of special cases in the
automatically generated node support functions.
Allegedly, only certain fields of RangeTblEntry are valid based on
rtekind. But exactly which ones seems to be documented and handled
inconsistently. It seems that over time, new RTE kinds have
"borrowed" fields that notionally belong to other RTE kinds, which is
technically not a problem but creates a bit of a mess when trying to
understand all this.
This patch removes the custom read/write functions for RangeTblEntry.
Those functions wanted to have a few fields at the front to make the
dump more legible; this is done now by moving the fields up in the
actual struct.
Discussion: https://www.postgresql.org/message-id/flat/4b27fc50-8cd6-46f5-ab20-88dbaadca645@eisentraut.org
TODO: clean up the documentation RangeTblEntry node
TODO: check how much this bloats stored rules
TODO: catversion
---
src/backend/nodes/outfuncs.c | 80 -----------------------------
src/backend/nodes/readfuncs.c | 92 ----------------------------------
src/include/nodes/parsenodes.h | 12 +++--
3 files changed, 8 insertions(+), 176 deletions(-)
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index dee2b9e87b2..26cfd60aed9 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -489,86 +489,6 @@ _outExtensibleNode(StringInfo str, const ExtensibleNode *node)
methods->nodeOut(str, node);
}
-static void
-_outRangeTblEntry(StringInfo str, const RangeTblEntry *node)
-{
- WRITE_NODE_TYPE("RANGETBLENTRY");
-
- /* put alias + eref first to make dump more legible */
- WRITE_NODE_FIELD(alias);
- WRITE_NODE_FIELD(eref);
- WRITE_ENUM_FIELD(rtekind, RTEKind);
-
- switch (node->rtekind)
- {
- case RTE_RELATION:
- WRITE_OID_FIELD(relid);
- WRITE_CHAR_FIELD(relkind);
- WRITE_INT_FIELD(rellockmode);
- WRITE_NODE_FIELD(tablesample);
- WRITE_UINT_FIELD(perminfoindex);
- break;
- case RTE_SUBQUERY:
- WRITE_NODE_FIELD(subquery);
- WRITE_BOOL_FIELD(security_barrier);
- /* we re-use these RELATION fields, too: */
- WRITE_OID_FIELD(relid);
- WRITE_CHAR_FIELD(relkind);
- WRITE_INT_FIELD(rellockmode);
- WRITE_UINT_FIELD(perminfoindex);
- break;
- case RTE_JOIN:
- WRITE_ENUM_FIELD(jointype, JoinType);
- WRITE_INT_FIELD(joinmergedcols);
- WRITE_NODE_FIELD(joinaliasvars);
- WRITE_NODE_FIELD(joinleftcols);
- WRITE_NODE_FIELD(joinrightcols);
- WRITE_NODE_FIELD(join_using_alias);
- break;
- case RTE_FUNCTION:
- WRITE_NODE_FIELD(functions);
- WRITE_BOOL_FIELD(funcordinality);
- break;
- case RTE_TABLEFUNC:
- WRITE_NODE_FIELD(tablefunc);
- break;
- case RTE_VALUES:
- WRITE_NODE_FIELD(values_lists);
- WRITE_NODE_FIELD(coltypes);
- WRITE_NODE_FIELD(coltypmods);
- WRITE_NODE_FIELD(colcollations);
- break;
- case RTE_CTE:
- WRITE_STRING_FIELD(ctename);
- WRITE_UINT_FIELD(ctelevelsup);
- WRITE_BOOL_FIELD(self_reference);
- WRITE_NODE_FIELD(coltypes);
- WRITE_NODE_FIELD(coltypmods);
- WRITE_NODE_FIELD(colcollations);
- break;
- case RTE_NAMEDTUPLESTORE:
- WRITE_STRING_FIELD(enrname);
- WRITE_FLOAT_FIELD(enrtuples);
- WRITE_NODE_FIELD(coltypes);
- WRITE_NODE_FIELD(coltypmods);
- WRITE_NODE_FIELD(colcollations);
- /* we re-use these RELATION fields, too: */
- WRITE_OID_FIELD(relid);
- break;
- case RTE_RESULT:
- /* no extra fields */
- break;
- default:
- elog(ERROR, "unrecognized RTE kind: %d", (int) node->rtekind);
- break;
- }
-
- WRITE_BOOL_FIELD(lateral);
- WRITE_BOOL_FIELD(inh);
- WRITE_BOOL_FIELD(inFromCl);
- WRITE_NODE_FIELD(securityQuals);
-}
-
static void
_outA_Expr(StringInfo str, const A_Expr *node)
{
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index b1e2f2b440a..54d3eecc1bc 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -343,98 +343,6 @@ _readA_Const(void)
READ_DONE();
}
-static RangeTblEntry *
-_readRangeTblEntry(void)
-{
- READ_LOCALS(RangeTblEntry);
-
- /* put alias + eref first to make dump more legible */
- READ_NODE_FIELD(alias);
- READ_NODE_FIELD(eref);
- READ_ENUM_FIELD(rtekind, RTEKind);
-
- switch (local_node->rtekind)
- {
- case RTE_RELATION:
- READ_OID_FIELD(relid);
- 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);
- /* we re-use these RELATION fields, too: */
- 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);
- READ_INT_FIELD(joinmergedcols);
- READ_NODE_FIELD(joinaliasvars);
- READ_NODE_FIELD(joinleftcols);
- READ_NODE_FIELD(joinrightcols);
- READ_NODE_FIELD(join_using_alias);
- break;
- case RTE_FUNCTION:
- READ_NODE_FIELD(functions);
- READ_BOOL_FIELD(funcordinality);
- break;
- case RTE_TABLEFUNC:
- READ_NODE_FIELD(tablefunc);
- /* The RTE must have a copy of the column type info, if any */
- if (local_node->tablefunc)
- {
- TableFunc *tf = local_node->tablefunc;
-
- local_node->coltypes = tf->coltypes;
- local_node->coltypmods = tf->coltypmods;
- local_node->colcollations = tf->colcollations;
- }
- break;
- case RTE_VALUES:
- READ_NODE_FIELD(values_lists);
- READ_NODE_FIELD(coltypes);
- READ_NODE_FIELD(coltypmods);
- READ_NODE_FIELD(colcollations);
- break;
- case RTE_CTE:
- READ_STRING_FIELD(ctename);
- READ_UINT_FIELD(ctelevelsup);
- READ_BOOL_FIELD(self_reference);
- READ_NODE_FIELD(coltypes);
- READ_NODE_FIELD(coltypmods);
- READ_NODE_FIELD(colcollations);
- break;
- case RTE_NAMEDTUPLESTORE:
- READ_STRING_FIELD(enrname);
- READ_FLOAT_FIELD(enrtuples);
- READ_NODE_FIELD(coltypes);
- READ_NODE_FIELD(coltypmods);
- READ_NODE_FIELD(colcollations);
- /* we re-use these RELATION fields, too: */
- READ_OID_FIELD(relid);
- break;
- case RTE_RESULT:
- /* no extra fields */
- break;
- default:
- elog(ERROR, "unrecognized RTE kind: %d",
- (int) local_node->rtekind);
- break;
- }
-
- READ_BOOL_FIELD(lateral);
- READ_BOOL_FIELD(inh);
- READ_BOOL_FIELD(inFromCl);
- READ_NODE_FIELD(securityQuals);
-
- READ_DONE();
-}
-
static A_Expr *
_readA_Expr(void)
{
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index d377f16a72b..8042c5d91ed 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -1018,8 +1018,6 @@ typedef enum RTEKind
typedef struct RangeTblEntry
{
- pg_node_attr(custom_read_write)
-
NodeTag type;
RTEKind rtekind; /* see above */
@@ -1030,6 +1028,14 @@ typedef struct RangeTblEntry
* code that is being actively worked on. FIXME someday.
*/
+ /*
+ * Fields valid in all RTEs:
+ *
+ * put alias + eref first to make dump more legible
+ */
+ 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 */
+
/*
* Fields valid for a plain relation RTE (else zero):
*
@@ -1188,8 +1194,6 @@ typedef struct RangeTblEntry
/*
* Fields valid in all RTEs:
*/
- 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 pg_node_attr(query_jumble_ignore); /* present in FROM clause? */
--
2.43.0