presto-main/src/main/java/io/prestosql/cost/StatsAndCosts.java/StatsAndCosts/getForSubplan
class StatsAndCosts:    public StatsAndCosts getForSubplan(PlanNode root)
    {
        Iterable<PlanNode> planIterator = Traverser.forTree(PlanNode::getSources)
                .depthFirstPreOrder(root);
        ImmutableMap.Builder<PlanNodeId, PlanNodeStatsEstimate> filteredStats = ImmutableMap.builder();
        ImmutableMap.Builder<PlanNodeId, PlanCostEstimate> filteredCosts = ImmutableMap.builder();
        for (PlanNode node : planIterator) {
            if (stats.containsKey(node.getId())) {
                filteredStats.put(node.getId(), stats.get(node.getId()));
            }
            if (costs.containsKey(node.getId())) {
                filteredCosts.put(node.getId(), costs.get(node.getId()));
            }
        }
        return new StatsAndCosts(filteredStats.build(), filteredCosts.build());
    }