class MultiPhasePlan implements Plan {

    @VisibleForTesting
    protected final Plan rootPlan;

    @VisibleForTesting
    protected final Map<LogicalPlan, SelectSymbol> dependencies;

    public static Plan createIfNeeded(Plan rootPlan, Map<LogicalPlan, SelectSymbol> dependencies) {
        if (dependencies.isEmpty()) {
            return rootPlan;
        }
        return new MultiPhasePlan(rootPlan, dependencies);
    }

    private MultiPhasePlan(Plan rootPlan, Map<LogicalPlan, SelectSymbol> dependencies) {
        this.rootPlan = rootPlan;
        this.dependencies = dependencies;
    }

    @Override
    public StatementType type() {
        return rootPlan.type();
    }

    @Override
    public void executeOrFail(DependencyCarrier dependencyCarrier,
                              PlannerContext plannerContext,
                              RowConsumer consumer,
                              Row params,
                              SubQueryResults subQueryResults) {<FILL_FUNCTION_BODY>}
}

        MultiPhaseExecutor.execute(dependencies, dependencyCarrier, plannerContext, params)
            .whenComplete((subQueryValues, failure) -> {
                if (failure == null) {
                    rootPlan.execute(dependencyCarrier, plannerContext, consumer, params, subQueryValues);
                } else {
                    consumer.accept(null, failure);
                }
            });
    
<no_super_class>