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/subselect.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/subselect.c')
-rw-r--r-- | src/backend/optimizer/plan/subselect.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index 575303b294a..4bdca59df64 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -1517,9 +1517,10 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink, return NULL; /* - * Scan the rangetable for relations with virtual generated columns, and - * replace all Var nodes in the subquery that reference these columns with - * the generation expressions. + * 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: we construct up an entirely dummy PlannerInfo for use here. This * is fine because only the "glob" and "parse" links will be used in this @@ -1534,7 +1535,7 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink, subroot.glob = root->glob; subroot.parse = subselect; subselect->jointree->quals = whereClause; - subselect = expand_virtual_generated_columns(&subroot); + subselect = preprocess_relation_rtes(&subroot); /* * Now separate out the WHERE clause again. |