diff options
author | Richard Guo <rguo@postgresql.org> | 2025-07-22 11:20:40 +0900 |
---|---|---|
committer | Richard Guo <rguo@postgresql.org> | 2025-07-22 11:20:40 +0900 |
commit | 904f6a593a06649f77597ab9a72ef97c21e39a93 (patch) | |
tree | cbfe3d1f8063598e775e0a270b4ab32b8394ae9d /src/backend/optimizer/plan/planner.c | |
parent | e0d05295268e3811e6743403cb779f21d1662426 (diff) |
Centralize collection of catalog info needed early in the planner
There are several pieces of catalog information that need to be
retrieved for a relation during the early stage of planning. These
include relhassubclass, which is used to clear the inh flag if the
relation has no children, as well as a column's attgenerated and
default value, which are needed to expand virtual generated columns.
More such information may be required in the future.
Currently, these pieces of catalog data are collected in multiple
places, resulting in repeated table_open/table_close calls for each
relation in the rangetable. This patch centralizes the collection of
all required early-stage catalog information into a single loop over
the rangetable, allowing each relation to be opened and closed only
once.
Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: Robert Haas <robertmhaas@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAMbWs4-bFJ1At4btk5wqbezdu8PLtQ3zv-aiaY3ry9Ymm=jgFQ@mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 31 |
1 files changed, 8 insertions, 23 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index fbbc42f1600..fc13d921d0c 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -721,13 +721,15 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, transform_MERGE_to_join(parse); /* - * Scan the rangetable for relations with virtual generated columns, and - * replace all Var nodes in the query that reference these columns with - * the generation expressions. Note that this step does not descend into - * sublinks and subqueries; if we pull up any sublinks or subqueries - * below, their rangetables are processed just before pulling them up. + * Scan the rangetable for relation RTEs and retrieve the necessary + * catalog information for each relation. Using this information, clear + * the inh flag for any relation that has no children, and expand virtual + * generated columns for any relation that contains them. Note that this + * step does not descend into sublinks and subqueries; if we pull up any + * sublinks or subqueries below, their relation RTEs are processed just + * before pulling them up. */ - parse = root->parse = expand_virtual_generated_columns(root); + parse = root->parse = preprocess_relation_rtes(root); /* * If the FROM clause is empty, replace it with a dummy RTE_RESULT RTE, so @@ -788,23 +790,6 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, switch (rte->rtekind) { - case RTE_RELATION: - if (rte->inh) - { - /* - * Check to see if the relation actually has any children; - * if not, clear the inh flag so we can treat it as a - * plain base relation. - * - * Note: this could give a false-positive result, if the - * rel once had children but no longer does. We used to - * be able to clear rte->inh later on when we discovered - * that, but no more; we have to handle such cases as - * full-fledged inheritance. - */ - rte->inh = has_subclass(rte->relid); - } - break; case RTE_JOIN: root->hasJoinRTEs = true; if (IS_OUTER_JOIN(rte->jointype)) |