Plan which depends on other plans to be executed first. E.g. for sub selects: select from t where x = (select 1) or x = (select 2) The two subselects would be the dependencies. The dependencies themselves may also be MultiPhasePlans.
| 46 | * The dependencies themselves may also be MultiPhasePlans. |
| 47 | */ |
| 48 | public class MultiPhasePlan implements Plan { |
| 49 | |
| 50 | @VisibleForTesting |
| 51 | protected final Plan rootPlan; |
| 52 | |
| 53 | @VisibleForTesting |
| 54 | protected final Map<LogicalPlan, SelectSymbol> dependencies; |
| 55 | |
| 56 | public static Plan createIfNeeded(Plan rootPlan, Map<LogicalPlan, SelectSymbol> dependencies) { |
| 57 | if (dependencies.isEmpty()) { |
| 58 | return rootPlan; |
| 59 | } |
| 60 | return new MultiPhasePlan(rootPlan, dependencies); |
| 61 | } |
| 62 | |
| 63 | private MultiPhasePlan(Plan rootPlan, Map<LogicalPlan, SelectSymbol> dependencies) { |
| 64 | this.rootPlan = rootPlan; |
| 65 | this.dependencies = dependencies; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public StatementType type() { |
| 70 | return rootPlan.type(); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public void executeOrFail(DependencyCarrier dependencyCarrier, |
| 75 | PlannerContext plannerContext, |
| 76 | RowConsumer consumer, |
| 77 | Row params, |
| 78 | SubQueryResults subQueryResults) { |
| 79 | MultiPhaseExecutor.execute(dependencies, dependencyCarrier, plannerContext, params) |
| 80 | .whenComplete((subQueryValues, failure) -> { |
| 81 | if (failure == null) { |
| 82 | Plan.execute(rootPlan, dependencyCarrier, plannerContext, consumer, params, subQueryValues); |
| 83 | } else { |
| 84 | consumer.accept(null, failure); |
| 85 | } |
| 86 | }); |
| 87 | } |
| 88 | } |
nothing calls this directly
no outgoing calls
no test coverage detected