mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
Expand virtual generated columns before sublink pull-up
Currently, we expand virtual generated columns after we have pulled up any SubLinks within the query's quals. This ensures that the virtual generated column references within SubLinks that should be transformed into joins are correctly expanded. This approach works well and has posed no issues. In an upcoming patch, we plan to centralize the collection of catalog information needed early in the planner. This will help avoid repeated table_open/table_close calls for relations in the rangetable. Since this information is required during sublink pull-up, we are moving the expansion of virtual generated columns to occur beforehand. To achieve this, if any EXISTS SubLinks can be pulled up, their rangetables are processed just before pulling them up. 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
This commit is contained in:
@@ -720,6 +720,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.
|
||||
*/
|
||||
parse = root->parse = expand_virtual_generated_columns(root);
|
||||
|
||||
/*
|
||||
* If the FROM clause is empty, replace it with a dummy RTE_RESULT RTE, so
|
||||
* that we don't need so many special cases to deal with that situation.
|
||||
@@ -743,14 +752,6 @@ subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root,
|
||||
*/
|
||||
preprocess_function_rtes(root);
|
||||
|
||||
/*
|
||||
* 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. Recursion issues here are handled in the
|
||||
* same way as for SubLinks.
|
||||
*/
|
||||
parse = root->parse = expand_virtual_generated_columns(root);
|
||||
|
||||
/*
|
||||
* Check to see if any subqueries in the jointree can be merged into this
|
||||
* query.
|
||||
|
||||
Reference in New Issue
Block a user