102102import org .elasticsearch .xpack .esql .plugin .TransportActionServices ;
103103import org .elasticsearch .xpack .esql .telemetry .PlanTelemetry ;
104104
105+ import java .util .ArrayList ;
105106import java .util .HashMap ;
106107import java .util .HashSet ;
107108import java .util .List ;
@@ -235,6 +236,7 @@ public void executeOptimizedPlan(
235236 ActionListener <Result > listener
236237 ) {
237238 if (explainMode ) {
239+ PhysicalPlan physicalPlan = logicalPlanToPhysicalPlan (optimizedPlan , request );
238240 String physicalPlanString = physicalPlan .toString ();
239241 List <Attribute > fields = List .of (
240242 new ReferenceAttribute (EMPTY , "role" , DataType .KEYWORD ),
@@ -247,11 +249,13 @@ public void executeOptimizedPlan(
247249 values .add (List .of ("coordinator" , "optimizedPhysicalPlan" , physicalPlanString ));
248250 var blocks = BlockUtils .fromList (PlannerUtils .NON_BREAKING_BLOCK_FACTORY , values );
249251 physicalPlan = new LocalSourceExec (Source .EMPTY , fields , LocalSupplier .of (blocks ));
252+ planRunner .run (physicalPlan , listener );
253+ } else {
254+ // TODO: this could be snuck into the underlying listener
255+ EsqlCCSUtils .updateExecutionInfoAtEndOfPlanning (executionInfo );
256+ // execute any potential subplans
257+ executeSubPlans (optimizedPlan , planRunner , executionInfo , request , listener );
250258 }
251- // TODO: this could be snuck into the underlying listener
252- EsqlCCSUtils .updateExecutionInfoAtEndOfPlanning (executionInfo );
253- // execute any potential subplans
254- executeSubPlans (optimizedPlan , planRunner , executionInfo , request , listener );
255259 }
256260
257261 private record LogicalPlanTuple (LogicalPlan nonStubbedSubPlan , LogicalPlan originalSubPlan ) {}
0 commit comments