From b2332f2ea03307ee6bc0e2e62fa5f364f7340039 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 11 Mar 2024 09:15:33 +0100 Subject: [PATCH v3 7/8] Simplify range_table_mutator_impl() and range_table_entry_walker_impl() This is part of an effort to reduce the number of special cases in the node support functions. This patch removes the switch on rtekind from range_table_mutator_impl() and range_table_entry_walker_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 | 110 ++++++++++++---------------------- 1 file changed, 37 insertions(+), 73 deletions(-) diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index db1b9bec13..410f700ee5 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -2699,41 +2699,20 @@ range_table_entry_walker_impl(RangeTblEntry *rte, if (WALK(rte)) return true; - switch (rte->rtekind) - { - case RTE_RELATION: - if (WALK(rte->tablesample)) - return true; - break; - case RTE_SUBQUERY: - if (!(flags & QTW_IGNORE_RT_SUBQUERIES)) - if (WALK(rte->subquery)) - return true; - break; - case RTE_JOIN: - if (!(flags & QTW_IGNORE_JOINALIASES)) - if (WALK(rte->joinaliasvars)) - return true; - break; - case RTE_FUNCTION: - if (WALK(rte->functions)) - return true; - break; - case RTE_TABLEFUNC: - if (WALK(rte->tablefunc)) - return true; - break; - case RTE_VALUES: - if (WALK(rte->values_lists)) - return true; - break; - case RTE_CTE: - case RTE_NAMEDTUPLESTORE: - case RTE_RESULT: - /* nothing to do */ - break; - } - + if (WALK(rte->tablesample)) + return true; + if (!(flags & QTW_IGNORE_RT_SUBQUERIES)) + if (WALK(rte->subquery)) + return true; + if (!(flags & QTW_IGNORE_JOINALIASES)) + if (WALK(rte->joinaliasvars)) + return true; + if (WALK(rte->functions)) + return true; + if (WALK(rte->tablefunc)) + return true; + if (WALK(rte->values_lists)) + return true; if (WALK(rte->securityQuals)) return true; @@ -3693,47 +3672,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.44.0