Remove Lateral input when it is not needed
Remove LateralJoinNode input when it is not needed (is scalar and
produces no column). In such LateralJoinNode is replaced by the
subquery.
Thank to that the code in PruneUnreferencedOutputs matches the code
of RemoveUnreferencedScalarLateralNodes.
@@ -788,6 +788,12 @@ public class PruneUnreferencedOutputs
.addAll(newCorrelation)
.build();
PlanNode input = context.rewrite(node.getInput(), inputContext);
+
+ // remove unused lateral nodes
+ if (intersection(ImmutableSet.copyOf(input.getOutputSymbols()), inputContext).isEmpty() && isScalar(input)) {
+ return subquery;
+ }
+
return new LateralJoinNode(node.getId(), input, subquery, newCorrelation, node.getType());
}
}
