@Override
  public Result apply(ApplyNode applyNode, Captures captures, Context context) {
    Set<Symbol> subqueryAssignmentsSymbols =
        applyNode.getSubqueryAssignments().values().stream()
            .flatMap(expression -> expression.inputs().stream())
            .collect(toImmutableSet());

    Optional<PlanNode> prunedSubquery =
        restrictOutputs(
            context.getIdAllocator(), applyNode.getSubquery(), subqueryAssignmentsSymbols);
    return prunedSubquery
        .map(
            subquery -> applyNode.replaceChildren(ImmutableList.of(applyNode.getInput(), subquery)))
        .map(Result::ofPlanNode)
        .orElse(Result.empty());
  }
This rule restricts outputs of ApplyNode's subquery to include only the symbols needed for
subqueryAssignments. Symbols from the subquery are not produced at ApplyNode's output. They are
only used for the assignments. Transforms:

<pre>
- Apply
     correlation: [corr_symbol]
     assignments:
         result_1 -> a in subquery_symbol_1,
         result_2 -> b > ALL subquery_symbol_2
   - Input (a, b, corr_symbol)
   - Subquery (subquery_symbol_1, subquery_symbol_2, subquery_symbol_3)
</pre>

Into:

<pre>
- Apply
     correlation: [corr_symbol]
     assignments:
         result_1 -> a in subquery_symbol_1,
         result_2 -> b > ALL subquery_symbol_2
   - Input (a, b, corr_symbol)
   - Project
         subquery_symbol_1 -> subquery_symbol_1
         subquery_symbol_2 -> subquery_symbol_2
       - Subquery (subquery_symbol_1, subquery_symbol_2, subquery_symbol_3)
</pre>

Note: ApplyNode's input symbols are produced on ApplyNode's output. They cannot be pruned without
outer context.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/planner/iterative/rule/PruneApplySourceColumns.java