diff --git a/core/trino-main/src/main/java/io/trino/execution/scheduler/policy/PhasedExecutionSchedule.java b/core/trino-main/src/main/java/io/trino/execution/scheduler/policy/PhasedExecutionSchedule.java index 6ac0964fc1bc..51fd6a51de5c 100644 --- a/core/trino-main/src/main/java/io/trino/execution/scheduler/policy/PhasedExecutionSchedule.java +++ b/core/trino-main/src/main/java/io/trino/execution/scheduler/policy/PhasedExecutionSchedule.java @@ -241,7 +241,7 @@ private void selectForExecution(StageExecution stage) return; } - if (fragmentDependency.outDegreeOf(stage.getFragment().getId()) > 0) { + if (activeStages.add(stage) && fragmentDependency.outDegreeOf(stage.getFragment().getId()) > 0) { // if there are any dependent stages then reschedule when stage is completed stage.addStateChangeListener(state -> { if (isStageCompleted(stage)) { @@ -249,7 +249,6 @@ private void selectForExecution(StageExecution stage) } }); } - activeStages.add(stage); } private void notifyReschedule()