presto-main/src/main/java/io/prestosql/execution/scheduler/PhasedExecutionSchedule.java/PhasedExecutionSchedule/addPhasesIfNecessary
class PhasedExecutionSchedule:    private void addPhasesIfNecessary()
    {
        // we want at least one source distributed phase in the active sources
        if (hasSourceDistributedStage(activeSources)) {
            return;
        }

        while (!schedulePhases.isEmpty()) {
            Set<SqlStageExecution> phase = schedulePhases.remove(0);
            activeSources.addAll(phase);
            if (hasSourceDistributedStage(phase)) {
                return;
            }
        }
    }