From df2898235350aafe82fb948b73e12a976e71237a Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 15 Jan 2024 11:23:39 +0100 Subject: [PATCH v2 3/4] Simplify range_table_mutator_impl() This is part of an effort to reduce the number of special cases in the 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 switch on rtekind from range_table_mutator_impl(). This should be fine because all the subroutines can handle unset/NULL fields. And it removes one more place that needs to track knowledge about which fields are valid when. Discussion: https://www.postgresql.org/message-id/flat/4b27fc50-8cd6-46f5-ab20-88dbaadca645@eisentraut.org --- src/backend/nodes/nodeFuncs.c | 61 +++++++++++++---------------------- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index e1a5bc7e95d..fe87238f195 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -3694,47 +3694,32 @@ range_table_mutator_impl(List *rtable, RangeTblEntry *newrte; FLATCOPY(newrte, rte, RangeTblEntry); - switch (rte->rtekind) + + MUTATE(newrte->tablesample, rte->tablesample, TableSampleClause *); + + if (!(flags & QTW_IGNORE_RT_SUBQUERIES)) + MUTATE(newrte->subquery, rte->subquery, Query *); + else { - case RTE_RELATION: - MUTATE(newrte->tablesample, rte->tablesample, - TableSampleClause *); - /* we don't bother to copy eref, aliases, etc; OK? */ - break; - case RTE_SUBQUERY: - if (!(flags & QTW_IGNORE_RT_SUBQUERIES)) - MUTATE(newrte->subquery, rte->subquery, Query *); - else - { - /* else, copy RT subqueries as-is */ - newrte->subquery = copyObject(rte->subquery); - } - break; - case RTE_JOIN: - if (!(flags & QTW_IGNORE_JOINALIASES)) - MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *); - else - { - /* else, copy join aliases as-is */ - newrte->joinaliasvars = copyObject(rte->joinaliasvars); - } - break; - case RTE_FUNCTION: - MUTATE(newrte->functions, rte->functions, List *); - break; - case RTE_TABLEFUNC: - MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *); - break; - case RTE_VALUES: - MUTATE(newrte->values_lists, rte->values_lists, List *); - break; - case RTE_CTE: - case RTE_NAMEDTUPLESTORE: - case RTE_RESULT: - /* nothing to do */ - break; + /* else, copy RT subqueries as-is */ + newrte->subquery = copyObject(rte->subquery); + } + + if (!(flags & QTW_IGNORE_JOINALIASES)) + MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *); + else + { + /* else, copy join aliases as-is */ + newrte->joinaliasvars = copyObject(rte->joinaliasvars); } + + MUTATE(newrte->functions, rte->functions, List *); + MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *); + MUTATE(newrte->values_lists, rte->values_lists, List *); MUTATE(newrte->securityQuals, rte->securityQuals, List *); + + /* we don't bother to copy eref, aliases, etc; OK? */ + newrt = lappend(newrt, newrte); } return newrt; -- 2.43.0