presto-main/src/main/java/io/prestosql/sql/planner/optimizations/QueryCardinalityUtil.java/QueryCardinalityUtil/applyLimit
class QueryCardinalityUtil:        private Range<Long> applyLimit(PlanNode source, long limit)
        {
            Range<Long> sourceCardinalityRange = source.accept(this, null);
            if (sourceCardinalityRange.hasUpperBound()) {
                limit = min(sourceCardinalityRange.upperEndpoint(), limit);
            }
            long lower = min(limit, sourceCardinalityRange.lowerEndpoint());
            return Range.closed(lower, limit);
        }