mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
Centralize fixups for mismatched nullingrels in nestloop params.
It turns out that the fixes we applied in commitsbfd332b3fand63e4f13d2were not nearly enough to solve the problem. We'd focused narrowly on subquery RTEs with lateral references, but lateral references can occur in several other RTE kinds such as function RTEs. Putting the same hack into half a dozen code paths seems quite unattractive. Hence, revert the code changes (but not the test cases) from those commits and instead solve it centrally in identify_current_nestloop_params(), as Richard proposed originally. This is a bit annoying because it could mask erroneous nullingrels in nestloop params that are generated from non-LATERAL parameterized paths; but on balance I don't see a better way. Maybe at some future time we'll be motivated to find a more rigorous approach to nestloop params, but that's not happening for beta2. Richard Guo and Tom Lane Discussion: https://postgr.es/m/CAMbWs48Jcw-NvnxT23WiHP324wG44DvzcH1j4hc0Zn+3sR9cfg@mail.gmail.com
This commit is contained in:
@@ -430,24 +430,6 @@ have_unsafe_outer_join_ref(PlannerInfo *root,
|
||||
* These are returned in parallel lists in *param_exprs and *operators.
|
||||
* We also set *binary_mode to indicate whether strict binary matching is
|
||||
* required.
|
||||
*
|
||||
* A complication is that innerrel's lateral_vars may contain nullingrel
|
||||
* markers that need adjustment. This occurs if we have applied outer join
|
||||
* identity 3,
|
||||
* (A leftjoin B on (Pab)) leftjoin C on (Pb*c)
|
||||
* = A leftjoin (B leftjoin C on (Pbc)) on (Pab)
|
||||
* and C contains lateral references to B. It's still safe to apply the
|
||||
* identity, but the parser will have created those references in the form
|
||||
* "b*" (i.e., with varnullingrels listing the A/B join), while what we will
|
||||
* have available from the nestloop's outer side is just "b". We deal with
|
||||
* that here by stripping the nullingrels down to what is available from the
|
||||
* outer side according to outerrel->relids.
|
||||
* That fixes matters for the case of forward application of identity 3.
|
||||
* If the identity was applied in the reverse direction, we will have
|
||||
* innerrel's lateral_vars containing too few nullingrel bits rather than
|
||||
* too many. Currently, that causes no problems because setrefs.c applies
|
||||
* only a subset check to nullingrels in NestLoopParams, but we'd have to
|
||||
* work harder if we ever want to tighten that check.
|
||||
*/
|
||||
static bool
|
||||
paraminfo_get_equal_hashops(PlannerInfo *root, ParamPathInfo *param_info,
|
||||
@@ -551,25 +533,6 @@ paraminfo_get_equal_hashops(PlannerInfo *root, ParamPathInfo *param_info,
|
||||
return false;
|
||||
}
|
||||
|
||||
/* OK, but adjust its nullingrels before adding it to result */
|
||||
expr = copyObject(expr);
|
||||
if (IsA(expr, Var))
|
||||
{
|
||||
Var *var = (Var *) expr;
|
||||
|
||||
var->varnullingrels = bms_intersect(var->varnullingrels,
|
||||
outerrel->relids);
|
||||
}
|
||||
else if (IsA(expr, PlaceHolderVar))
|
||||
{
|
||||
PlaceHolderVar *phv = (PlaceHolderVar *) expr;
|
||||
|
||||
phv->phnullingrels = bms_intersect(phv->phnullingrels,
|
||||
outerrel->relids);
|
||||
}
|
||||
else
|
||||
Assert(false);
|
||||
|
||||
*operators = lappend_oid(*operators, typentry->eq_opr);
|
||||
*param_exprs = lappend(*param_exprs, expr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user