* on top, then we can't "look through" that node -- indeed, what's going to be
* relevant for our purposes is the ElidedNode on top of that plan node, rather
* than the plan node itself.
+ *
+ * If there are multiple elided nodes, we want that one that would have been
+ * uppermost in the plan tree prior to setrefs processing; we expect to find
+ * that one last in the list of elided nodes.
*/
static pgpa_join_strategy
pgpa_decompose_join(PlannedStmt *pstmt, Plan *plan,
ElidedNode *elidedinner;
pgpa_join_strategy strategy;
- elidedouter = pgpa_first_elided_node(pstmt, outerplan);
- elidedinner = pgpa_first_elided_node(pstmt, innerplan);
+ elidedouter = pgpa_last_elided_node(pstmt, outerplan);
+ elidedinner = pgpa_last_elided_node(pstmt, innerplan);
switch (nodeTag(plan))
{
if (elidedouter == NULL && IsA(outerplan, Sort))
{
outerplan = outerplan->lefttree;
- elidedouter = pgpa_first_elided_node(pstmt, outerplan);
+ elidedouter = pgpa_last_elided_node(pstmt, outerplan);
}
if (elidedinner == NULL && IsA(innerplan, Sort))
{
innerplan = innerplan->lefttree;
- elidedinner = pgpa_first_elided_node(pstmt, innerplan);
+ elidedinner = pgpa_last_elided_node(pstmt, innerplan);
}
if (elidedinner == NULL && IsA(innerplan, Material))
{
innerplan = innerplan->lefttree;
- elidedinner = pgpa_first_elided_node(pstmt, innerplan);
+ elidedinner = pgpa_last_elided_node(pstmt, innerplan);
strategy = JSTRAT_MERGE_JOIN_MATERIALIZE;
}
else
if (elidedinner == NULL && IsA(innerplan, Material))
{
innerplan = innerplan->lefttree;
- elidedinner = pgpa_first_elided_node(pstmt, innerplan);
+ elidedinner = pgpa_last_elided_node(pstmt, innerplan);
strategy = JSTRAT_NESTED_LOOP_MATERIALIZE;
}
else if (elidedinner == NULL && IsA(innerplan, Memoize))
{
innerplan = innerplan->lefttree;
- elidedinner = pgpa_first_elided_node(pstmt, innerplan);
+ elidedinner = pgpa_last_elided_node(pstmt, innerplan);
strategy = JSTRAT_NESTED_LOOP_MEMOIZE;
}
else
Assert(IsA(innerplan, Hash));
Assert(elidedinner == NULL);
innerplan = innerplan->lefttree;
- elidedinner = pgpa_first_elided_node(pstmt, innerplan);
+ elidedinner = pgpa_last_elided_node(pstmt, innerplan);
strategy = JSTRAT_HASH_JOIN;
break;