diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/nodes/nodes.h | 1 | ||||
-rw-r--r-- | src/include/nodes/relation.h | 44 | ||||
-rw-r--r-- | src/include/optimizer/cost.h | 5 | ||||
-rw-r--r-- | src/include/optimizer/pathnode.h | 8 | ||||
-rw-r--r-- | src/include/optimizer/planmain.h | 2 | ||||
-rw-r--r-- | src/include/optimizer/planner.h | 2 |
6 files changed, 54 insertions, 8 deletions
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h index b96a30b60ed..438a1d98630 100644 --- a/src/include/nodes/nodes.h +++ b/src/include/nodes/nodes.h @@ -235,6 +235,7 @@ typedef enum NodeTag T_RestrictInfo, T_PlaceHolderVar, T_SpecialJoinInfo, + T_LateralJoinInfo, T_AppendRelInfo, T_PlaceHolderInfo, T_MinMaxAggInfo, diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index 8238981c289..43c2956fdf5 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -193,7 +193,9 @@ typedef struct PlannerInfo List *full_join_clauses; /* list of RestrictInfos for * mergejoinable full join clauses */ - List *join_info_list; /* list of SpecialJoinInfos */ + List *join_info_list; /* list of SpecialJoinInfos */ + + List *lateral_info_list; /* list of LateralJoinInfos */ List *append_rel_list; /* list of AppendRelInfos */ @@ -223,6 +225,7 @@ typedef struct PlannerInfo bool hasInheritedTarget; /* true if parse->resultRelation is an * inheritance child rel */ bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */ + bool hasLateralRTEs; /* true if any RTEs are marked LATERAL */ bool hasHavingQual; /* true if havingQual was non-null */ bool hasPseudoConstantQuals; /* true if any RestrictInfo has * pseudoconstant = true */ @@ -300,8 +303,8 @@ typedef struct PlannerInfo * we need to output from this relation. * List is in no particular order, but all rels of an * appendrel set must use corresponding orders. - * NOTE: in a child relation, may contain RowExpr or - * ConvertRowtypeExpr representing a whole-row Var. + * NOTE: in an appendrel child relation, may contain + * arbitrary expressions pulled up from a subquery! * pathlist - List of Path nodes, one for each potentially useful * method of generating the relation * ppilist - ParamPathInfo nodes for parameterized Paths, if any @@ -330,6 +333,10 @@ typedef struct PlannerInfo * the attribute is needed as part of final targetlist * attr_widths - cache space for per-attribute width estimates; * zero means not computed yet + * lateral_vars - lateral cross-references of rel, if any (list of + * Vars and PlaceHolderVars) + * lateral_relids - required outer rels for LATERAL, as a Relids set + * (for child rels this can be more than lateral_vars) * indexlist - list of IndexOptInfo nodes for relation's indexes * (always NIL if it's not a table) * pages - number of disk pages in relation (zero if not a table) @@ -417,6 +424,8 @@ typedef struct RelOptInfo AttrNumber max_attr; /* largest attrno of rel */ Relids *attr_needed; /* array indexed [min_attr .. max_attr] */ int32 *attr_widths; /* array indexed [min_attr .. max_attr] */ + List *lateral_vars; /* LATERAL Vars and PHVs referenced by rel */ + Relids lateral_relids; /* minimum parameterization of rel */ List *indexlist; /* list of IndexOptInfo */ BlockNumber pages; /* size estimates derived from pg_class */ double tuples; @@ -1324,6 +1333,35 @@ typedef struct SpecialJoinInfo } SpecialJoinInfo; /* + * "Lateral join" info. + * + * Lateral references in subqueries constrain the join order in a way that's + * somewhat like outer joins, though different in detail. We construct one or + * more LateralJoinInfos for each RTE with lateral references, and add them to + * the PlannerInfo node's lateral_info_list. + * + * lateral_rhs is the relid of a baserel with lateral references, and + * lateral_lhs is a set of relids of baserels it references, all of which + * must be present on the LHS to compute a parameter needed by the RHS. + * Typically, lateral_lhs is a singleton, but it can include multiple rels + * if the RHS references a PlaceHolderVar with a multi-rel ph_eval_at level. + * We disallow joining to only part of the LHS in such cases, since that would + * result in a join tree with no convenient place to compute the PHV. + * + * When an appendrel contains lateral references (eg "LATERAL (SELECT x.col1 + * UNION ALL SELECT y.col2)"), the LateralJoinInfos reference the parent + * baserel not the member otherrels, since it is the parent relid that is + * considered for joining purposes. + */ + +typedef struct LateralJoinInfo +{ + NodeTag type; + Index lateral_rhs; /* a baserel containing lateral refs */ + Relids lateral_lhs; /* some base relids it references */ +} LateralJoinInfo; + +/* * Append-relation info. * * When we expand an inheritable table or a UNION-ALL subselect into an diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h index 7f6870e5f08..1cc9a7e5397 100644 --- a/src/include/optimizer/cost.h +++ b/src/include/optimizer/cost.h @@ -77,14 +77,15 @@ extern void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root); extern void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root); extern void cost_bitmap_tree_node(Path *path, Cost *cost, Selectivity *selec); extern void cost_tidscan(Path *path, PlannerInfo *root, - RelOptInfo *baserel, List *tidquals); + RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info); extern void cost_subqueryscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info); extern void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info); extern void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info); -extern void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel); +extern void cost_ctescan(Path *path, PlannerInfo *root, + RelOptInfo *baserel, ParamPathInfo *param_info); extern void cost_recursive_union(Plan *runion, Plan *nrterm, Plan *rterm); extern void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h index 33f2bf13c09..de889fbfa68 100644 --- a/src/include/optimizer/pathnode.h +++ b/src/include/optimizer/pathnode.h @@ -55,7 +55,7 @@ extern BitmapOrPath *create_bitmap_or_path(PlannerInfo *root, RelOptInfo *rel, List *bitmapquals); extern TidPath *create_tidscan_path(PlannerInfo *root, RelOptInfo *rel, - List *tidquals); + List *tidquals, Relids required_outer); extern AppendPath *create_append_path(RelOptInfo *rel, List *subpaths, Relids required_outer); extern MergeAppendPath *create_merge_append_path(PlannerInfo *root, @@ -73,8 +73,10 @@ extern Path *create_functionscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer); extern Path *create_valuesscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer); -extern Path *create_ctescan_path(PlannerInfo *root, RelOptInfo *rel); -extern Path *create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel); +extern Path *create_ctescan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); +extern Path *create_worktablescan_path(PlannerInfo *root, RelOptInfo *rel, + Relids required_outer); extern ForeignPath *create_foreignscan_path(PlannerInfo *root, RelOptInfo *rel, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h index 5a9e677f94f..c395d4292c8 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -94,6 +94,8 @@ extern void add_base_rels_to_query(PlannerInfo *root, Node *jtnode); extern void build_base_rel_tlists(PlannerInfo *root, List *final_tlist); extern void add_vars_to_targetlist(PlannerInfo *root, List *vars, Relids where_needed, bool create_new_ph); +extern void find_lateral_references(PlannerInfo *root); +extern void create_lateral_join_info(PlannerInfo *root); extern List *deconstruct_jointree(PlannerInfo *root); extern void distribute_restrictinfo_to_rels(PlannerInfo *root, RestrictInfo *restrictinfo); diff --git a/src/include/optimizer/planner.h b/src/include/optimizer/planner.h index af0c817a43d..35f16e8fb71 100644 --- a/src/include/optimizer/planner.h +++ b/src/include/optimizer/planner.h @@ -42,6 +42,8 @@ extern bool is_dummy_plan(Plan *plan); extern Expr *expression_planner(Expr *expr); +extern Expr *preprocess_phv_expression(PlannerInfo *root, Expr *expr); + extern bool plan_cluster_use_sort(Oid tableOid, Oid indexOid); #endif /* PLANNER_H */ |