presto-main/src/main/java/io/prestosql/cost/LimitStatsRule.java/LimitStatsRule/doCalculate
class LimitStatsRule:    @Override
    protected Optional<PlanNodeStatsEstimate> doCalculate(LimitNode node, StatsProvider statsProvider, Lookup lookup, Session session, TypeProvider types)
    {
        PlanNodeStatsEstimate sourceStats = statsProvider.getStats(node.getSource());
        if (sourceStats.getOutputRowCount() <= node.getCount()) {
            return Optional.of(sourceStats);
        }

        // LIMIT actually limits (or when there was no row count estimated for source)
        return Optional.of(PlanNodeStatsEstimate.buildFrom(sourceStats)
                .setOutputRowCount(node.getCount())
                .build());
    }