mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
Fix up planner infrastructure to support LATERAL properly.
This patch takes care of a number of problems having to do with failure to choose valid join orders and incorrect handling of lateral references pulled up from subqueries. Notable changes: * Add a LateralJoinInfo data structure similar to SpecialJoinInfo, to represent join ordering constraints created by lateral references. (I first considered extending the SpecialJoinInfo structure, but the semantics are different enough that a separate data structure seems better.) Extend join_is_legal() and related functions to prevent trying to form unworkable joins, and to ensure that we will consider joins that satisfy lateral references even if the joins would be clauseless. * Fill in the infrastructure needed for the last few types of relation scan paths to support parameterization. We'd have wanted this eventually anyway, but it is necessary now because a relation that gets pulled up out of a UNION ALL subquery may acquire a reltargetlist containing lateral references, meaning that its paths *have* to be parameterized whether or not we have any code that can push join quals down into the scan. * Compute data about lateral references early in query_planner(), and save in RelOptInfo nodes, to avoid repetitive calculations later. * Assorted corner-case bug fixes. There's probably still some bugs left, but this is a lot closer to being real than it was before.
This commit is contained in:
@@ -1026,11 +1026,14 @@ pull_up_simple_subquery(PlannerInfo *root, Node *jtnode, RangeTblEntry *rte,
|
||||
subroot->append_rel_list);
|
||||
|
||||
/*
|
||||
* We don't have to do the equivalent bookkeeping for outer-join info,
|
||||
* because that hasn't been set up yet. placeholder_list likewise.
|
||||
* We don't have to do the equivalent bookkeeping for outer-join or
|
||||
* LATERAL info, because that hasn't been set up yet. placeholder_list
|
||||
* likewise.
|
||||
*/
|
||||
Assert(root->join_info_list == NIL);
|
||||
Assert(subroot->join_info_list == NIL);
|
||||
Assert(root->lateral_info_list == NIL);
|
||||
Assert(subroot->lateral_info_list == NIL);
|
||||
Assert(root->placeholder_list == NIL);
|
||||
Assert(subroot->placeholder_list == NIL);
|
||||
|
||||
@@ -2319,6 +2322,7 @@ substitute_multiple_relids_walker(Node *node,
|
||||
}
|
||||
/* Shouldn't need to handle planner auxiliary nodes here */
|
||||
Assert(!IsA(node, SpecialJoinInfo));
|
||||
Assert(!IsA(node, LateralJoinInfo));
|
||||
Assert(!IsA(node, AppendRelInfo));
|
||||
Assert(!IsA(node, PlaceHolderInfo));
|
||||
Assert(!IsA(node, MinMaxAggInfo));
|
||||
|
||||
@@ -1746,6 +1746,7 @@ adjust_appendrel_attrs_mutator(Node *node,
|
||||
}
|
||||
/* Shouldn't need to handle planner auxiliary nodes here */
|
||||
Assert(!IsA(node, SpecialJoinInfo));
|
||||
Assert(!IsA(node, LateralJoinInfo));
|
||||
Assert(!IsA(node, AppendRelInfo));
|
||||
Assert(!IsA(node, PlaceHolderInfo));
|
||||
Assert(!IsA(node, MinMaxAggInfo));
|
||||
|
||||
Reference in New Issue
Block a user