3333import com .apple .foundationdb .record .query .plan .QueryPlanInfoKeys ;
3434import com .apple .foundationdb .record .query .plan .QueryPlanResult ;
3535import com .apple .foundationdb .record .query .plan .cascades .CascadesPlanner ;
36+ import com .apple .foundationdb .record .query .plan .cascades .PlannerPhase ;
3637import com .apple .foundationdb .record .query .plan .cascades .Reference ;
3738import com .apple .foundationdb .record .query .plan .cascades .debug .Debugger ;
3839import com .apple .foundationdb .record .query .plan .cascades .debug .Stats ;
8889import java .sql .Struct ;
8990import java .util .ArrayList ;
9091import java .util .Collections ;
92+
9193import java .util .List ;
9294import java .util .Map ;
9395import java .util .Objects ;
@@ -296,7 +298,11 @@ private RelationalResultSet executeExplain(@Nonnull ContinuationImpl parsedConti
296298 DataType .StructType .Field .from ("TRANSFORM_YIELD_COUNT" , DataType .Primitives .LONG .type (), 4 ),
297299 DataType .StructType .Field .from ("INSERT_TIME_NS" , DataType .Primitives .LONG .type (), 5 ),
298300 DataType .StructType .Field .from ("INSERT_NEW_COUNT" , DataType .Primitives .LONG .type (), 6 ),
299- DataType .StructType .Field .from ("INSERT_REUSED_COUNT" , DataType .Primitives .LONG .type (), 7 )),
301+ DataType .StructType .Field .from ("INSERT_REUSED_COUNT" , DataType .Primitives .LONG .type (), 7 ),
302+ DataType .StructType .Field .from ("REWRITING_PHASE_TASK_COUNT" , DataType .Primitives .LONG .type (), 8 ),
303+ DataType .StructType .Field .from ("PLANNING_PHASE_TASK_COUNT" , DataType .Primitives .LONG .type (), 9 ),
304+ DataType .StructType .Field .from ("REWRITING_PHASE_TASKS_TOTAL_TIME_NS" , DataType .Primitives .LONG .type (), 10 ),
305+ DataType .StructType .Field .from ("PLANNING_PHASE_TASKS_TOTAL_TIME_NS" , DataType .Primitives .LONG .type (), 11 )),
300306 true );
301307 final var explainStructType = DataType .StructType .from (
302308 "EXPLAIN" , List .of (
@@ -320,25 +326,35 @@ private RelationalResultSet executeExplain(@Nonnull ContinuationImpl parsedConti
320326 plannerMetrics = null ;
321327 } else {
322328 final var plannerEventClassStatsMap = plannerStatsMaps .getEventClassStatsMap ();
323- final var executingTasksStats =
329+
330+ final var aggregateExecutingTasksStats =
324331 Optional .ofNullable (plannerEventClassStatsMap .get (Debugger .ExecutingTaskEvent .class ));
325- final var transformRuleCallStats =
332+ final var aggregateTransformRuleCallStats =
326333 Optional .ofNullable (plannerEventClassStatsMap .get (Debugger .TransformRuleCallEvent .class ));
327- final var insertIntoMemoStats =
334+ final var aggregateInsertIntoMemoStats =
328335 Optional .ofNullable (plannerEventClassStatsMap .get (Debugger .InsertIntoMemoEvent .class ));
329336
337+ final var executingTasksStatsForRewritingPhase =
338+ plannerStatsMaps .getEventWithStateClassStatsMapByPlannerPhase (PlannerPhase .REWRITING )
339+ .map (m -> m .get (Debugger .ExecutingTaskEvent .class ));
340+ final var executingTasksStatsForPlanningPhase =
341+ plannerStatsMaps .getEventWithStateClassStatsMapByPlannerPhase (PlannerPhase .PLANNING )
342+ .map (m -> m .get (Debugger .ExecutingTaskEvent .class ));
343+
330344 plannerMetrics =
331345 new ImmutableRowStruct (new ArrayRow (
332- executingTasksStats .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
333- executingTasksStats .map (Stats ::getTotalTimeInNs ).orElse (0L ),
334- transformRuleCallStats .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
335- transformRuleCallStats .map (Stats ::getOwnTimeInNs ).orElse (0L ),
336- transformRuleCallStats .map (s -> s .getCount (Debugger .Location .YIELD )).orElse (0L ),
337- insertIntoMemoStats .map (Stats ::getOwnTimeInNs ).orElse (0L ),
338- insertIntoMemoStats .map (s -> s .getCount (Debugger .Location .NEW )).orElse (0L ),
339- insertIntoMemoStats .map (s -> s .getCount (Debugger .Location .REUSED )).orElse (0L ),
340- parsedContinuation .getVersion (),
341- parsedContinuation .getCompiledStatement () == null ? null : parsedContinuation .getCompiledStatement ().getPlanSerializationMode ()
346+ aggregateExecutingTasksStats .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
347+ aggregateExecutingTasksStats .map (Stats ::getTotalTimeInNs ).orElse (0L ),
348+ aggregateTransformRuleCallStats .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
349+ aggregateTransformRuleCallStats .map (Stats ::getOwnTimeInNs ).orElse (0L ),
350+ aggregateTransformRuleCallStats .map (s -> s .getCount (Debugger .Location .YIELD )).orElse (0L ),
351+ aggregateInsertIntoMemoStats .map (Stats ::getOwnTimeInNs ).orElse (0L ),
352+ aggregateInsertIntoMemoStats .map (s -> s .getCount (Debugger .Location .NEW )).orElse (0L ),
353+ aggregateInsertIntoMemoStats .map (s -> s .getCount (Debugger .Location .REUSED )).orElse (0L ),
354+ executingTasksStatsForRewritingPhase .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
355+ executingTasksStatsForPlanningPhase .map (s -> s .getCount (Debugger .Location .BEGIN )).orElse (0L ),
356+ executingTasksStatsForRewritingPhase .map (Stats ::getTotalTimeInNs ).orElse (0L ),
357+ executingTasksStatsForPlanningPhase .map (Stats ::getTotalTimeInNs ).orElse (0L )
342358 ), RelationalStructMetaData .of (plannerMetricsStructType ));
343359 }
344360
0 commit comments