presto-main/src/main/java/io/prestosql/sql/planner/iterative/rule/RemoveUnreferencedScalarSubqueries.java/RemoveUnreferencedScalarSubqueries/apply
class RemoveUnreferencedScalarSubqueries:    @Override
    public Result apply(CorrelatedJoinNode correlatedJoinNode, Captures captures, Context context)
    {
        PlanNode input = correlatedJoinNode.getInput();
        PlanNode subquery = correlatedJoinNode.getSubquery();

        if (isUnreferencedScalar(input, context.getLookup())) {
            return Result.ofPlanNode(subquery);
        }

        if (isUnreferencedScalar(subquery, context.getLookup())) {
            return Result.ofPlanNode(input);
        }

        return Result.empty();
    }