Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3f1a350

Browse files
guofengrichardCommitfest Bot
authored and
Commitfest Bot
committed
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.
1 parent ab5de28 commit 3f1a350

File tree

4 files changed

+190
-151
lines changed

4 files changed

+190
-151
lines changed

src/backend/optimizer/plan/planner.c

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -721,13 +721,15 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
721721
transform_MERGE_to_join(parse);
722722

723723
/*
724-
* Scan the rangetable for relations with virtual generated columns, and
725-
* replace all Var nodes in the query that reference these columns with
726-
* the generation expressions. Note that this step does not descend into
727-
* sublinks and subqueries; if we pull up any sublinks or subqueries
728-
* below, their rangetables are processed just before pulling them up.
724+
* Scan the rangetable for relation RTEs and retrieve the necessary
725+
* catalog information for each relation. Using this information, clear
726+
* the inh flag for any relation that has no children, and expand virtual
727+
* generated columns for any relation that contains them. Note that this
728+
* step does not descend into sublinks and subqueries; if we pull up any
729+
* sublinks or subqueries below, their relation RTEs are processed just
730+
* before pulling them up.
729731
*/
730-
parse = root->parse = expand_virtual_generated_columns(root);
732+
parse = root->parse = preprocess_relation_rtes(root);
731733

732734
/*
733735
* 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,
788790

789791
switch (rte->rtekind)
790792
{
791-
case RTE_RELATION:
792-
if (rte->inh)
793-
{
794-
/*
795-
* Check to see if the relation actually has any children;
796-
* if not, clear the inh flag so we can treat it as a
797-
* plain base relation.
798-
*
799-
* Note: this could give a false-positive result, if the
800-
* rel once had children but no longer does. We used to
801-
* be able to clear rte->inh later on when we discovered
802-
* that, but no more; we have to handle such cases as
803-
* full-fledged inheritance.
804-
*/
805-
rte->inh = has_subclass(rte->relid);
806-
}
807-
break;
808793
case RTE_JOIN:
809794
root->hasJoinRTEs = true;
810795
if (IS_OUTER_JOIN(rte->jointype))

src/backend/optimizer/plan/subselect.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,9 +1489,10 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink,
14891489
return NULL;
14901490

14911491
/*
1492-
* Scan the rangetable for relations with virtual generated columns, and
1493-
* replace all Var nodes in the subquery that reference these columns with
1494-
* the generation expressions.
1492+
* Scan the rangetable for relation RTEs and retrieve the necessary
1493+
* catalog information for each relation. Using this information, clear
1494+
* the inh flag for any relation that has no children, and expand virtual
1495+
* generated columns for any relation that contains them.
14951496
*
14961497
* Note: we construct up an entirely dummy PlannerInfo for use here. This
14971498
* is fine because only the "glob" and "parse" links will be used in this
@@ -1501,7 +1502,7 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink,
15011502
subroot.type = T_PlannerInfo;
15021503
subroot.glob = root->glob;
15031504
subroot.parse = subselect;
1504-
subselect = expand_virtual_generated_columns(&subroot);
1505+
subselect = preprocess_relation_rtes(&subroot);
15051506

15061507
/*
15071508
* Separate out the WHERE clause. (We could theoretically also remove

0 commit comments

Comments
 (0)