presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/RemoveRedundantTopN.java/RemoveRedundantTopN/apply
class RemoveRedundantTopN:    @Override
    public Result apply(TopNNode node, Captures captures, Context context)
    {
        if (node.getCount() == 0) {
            return Result.ofPlanNode(new ValuesNode(node.getId(), node.getOutputSymbols(), ImmutableList.of()));
        }
        if (isScalar(node.getSource(), context.getLookup())) {
            return Result.ofPlanNode(node.getSource());
        }
        if (isAtMost(node.getSource(), context.getLookup(), node.getCount())) {
            return Result.ofPlanNode(new SortNode(context.getIdAllocator().getNextId(), node.getSource(), node.getOrderingScheme(), false));
        }
        return Result.empty();
    }