presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/PushLimitThroughOuterJoin.java/PushLimitThroughOuterJoin/apply
class PushLimitThroughOuterJoin:    @Override
    public Result apply(LimitNode parent, Captures captures, Context context)
    {
        JoinNode joinNode = captures.get(CHILD);
        PlanNode left = joinNode.getLeft();
        PlanNode right = joinNode.getRight();

        if (joinNode.getType() == LEFT && !isAtMost(left, context.getLookup(), parent.getCount())) {
            return Result.ofPlanNode(
                    parent.replaceChildren(ImmutableList.of(
                            joinNode.replaceChildren(ImmutableList.of(
                                    new LimitNode(context.getIdAllocator().getNextId(), left, parent.getCount(), true),
                                    right)))));
        }

        if (joinNode.getType() == RIGHT && !isAtMost(right, context.getLookup(), parent.getCount())) {
            return Result.ofPlanNode(
                    parent.replaceChildren(ImmutableList.of(
                            joinNode.replaceChildren(ImmutableList.of(
                                    left,
                                    new LimitNode(context.getIdAllocator().getNextId(), right, parent.getCount(), true))))));
        }

        return Result.empty();
    }