presto-main/src/main/java/io/prestosql/sql/planner/optimizations/PlanNodeSearcher.java/PlanNodeSearcher/removeAllRecursive
class PlanNodeSearcher:    private PlanNode removeAllRecursive(PlanNode node)
    {
        node = lookup.resolve(node);

        if (where.test(node)) {
            checkArgument(
                    node.getSources().size() == 1,
                    "Unable to remove plan node as it contains 0 or more than 1 children");
            return node.getSources().get(0);
        }
        if (recurseOnlyWhen.test(node)) {
            List<PlanNode> sources = node.getSources().stream()
                    .map(this::removeAllRecursive)
                    .collect(toImmutableList());
            return replaceChildren(node, sources);
        }
        return node;
    }