presto-main/src/main/java/io/prestosql/sql/planner/optimizations/PlanNodeDecorrelator.java/DecorrelatingVisitor/visitLimit
class DecorrelatingVisitor:        @Override
        public Optional<DecorrelationResult> visitLimit(LimitNode node, Void context)
        {
            if (node.getCount() == 0 || node.isWithTies()) {
                return Optional.empty();
            }

            Optional<DecorrelationResult> childDecorrelationResultOptional = node.getSource().accept(this, null);
            if (!childDecorrelationResultOptional.isPresent()) {
                return Optional.empty();
            }

            DecorrelationResult childDecorrelationResult = childDecorrelationResultOptional.get();
            if (childDecorrelationResult.atMostSingleRow) {
                return childDecorrelationResultOptional;
            }

            if (node.getCount() == 1) {
                return rewriteLimitWithRowCountOne(childDecorrelationResult, node.getId());
            }
            return rewriteLimitWithRowCountGreaterThanOne(childDecorrelationResult, node);
        }